Implement LWG3843 (std::expected<T,E>::value() & assumes E is copy constructible)
https://wg21.link/LWG3843
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
LGTM, but I haven't been here long enough to feel like I can accept this on behalf of libc++ team :-)
Thanks for the patch! I really appreciate the added .verify.pass.cpp tests. I have a few questions but this basically LGTM.
libcxx/include/__expected/expected.h | ||
---|---|---|
565 | I don't think it's possible to test this added as_const, since IIUC this is a no-op given that this member function has a const& qualifier. Right? | |
573 | I don't think we're testing the added as_const here. I think we could test this by using an error type with two constructors: Error(Error const&); Error(Error&); We'd make sure that the first one got called, not the second one. Does that make sense? | |
libcxx/test/libcxx/utilities/expected/expected.expected/value.observers.verify.cpp | ||
124–129 | Right? |
libcxx/test/std/utilities/expected/expected.expected/observers/value.pass.cpp | ||
---|---|---|
23–39 | I don't think this tests what you intend to test. If you remove as_const in the & overload, does this test suddenly fail? I don't think it would, since you're still providing the declaration of the member function. Instead, I think what you want is this: bool ref_called = true; bool const_ref_called = true; struct Foo { Foo(Foo const&) { const_ref_called = true; } Foo(Foo&) { ref_called = true; } }; int main() { std::expected<int, Foo> e; try { e.value(); catch (std::bad_expected_access const&) { assert(const_ref_called); } } Obviously this is a poor way to test this, but I think you see the point I'm trying to make? |
I don't think it's possible to test this added as_const, since IIUC this is a no-op given that this member function has a const& qualifier. Right?