[llvm-branch-commits] [libcxx] [libc++] Implement std::move_only_function (P0288R9) (PR #94670)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jun 7 06:01:52 PDT 2024


EricWF wrote:

Oh, I just noticed there are no tests for exception safety. Could you please add some throwing types? (Or perhaps I just missed those tests?).

Currently this code terminates:
```
#include <functional>
#include <cassert>

struct ThrowsOnConstruct {
  explicit ThrowsOnConstruct(int x) : value(x) { if (x == 42) throw 42; }
  ThrowsOnConstruct(ThrowsOnConstruct const&) = delete;
  ThrowsOnConstruct(ThrowsOnConstruct && other) : value(other.value) { if (other.value == 101) throw 101; other.value = -1; }

  ~ThrowsOnConstruct() {
    assert(value != -1);
    value = -1;
  }

  int operator()() const noexcept { return value; }

  int value;
};

int main() {
  using MV = std::move_only_function<int() const>;
  try {
    MV f(ThrowsOnConstruct(101));
  } catch (...) {
  }
}
```

In particular, I don't think this constructor can be `noexcept`. 

I also think there are some missing tests for reference_wrapper. 

https://github.com/llvm/llvm-project/pull/94670


More information about the llvm-branch-commits mailing list