Date
2023-02-09.09:42:20
Message id
13163

Content

[expected.object.obs] p9 says:

Throws: bad_expected_access(error()) if has_value() is false.

But if error() returns a reference to a move-only type then it can't be copied and the function body is ill-formed. Should it be constrained with is_copy_constructible_v<E>? Or just mandate it?

Similarly, the value()&& and value() const&& overloads require is_move_constructible_v<E> to be true for bad_expected_access(std::move(error())) to be valid. Casey Carter pointed out they also require it to be copyable so that the exception can be thrown, as per [except.throw] p5.