-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[libc++] Implement LWG3940: std::expected<void, E>::value() also needs E to be copy constructible #71819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc++] Implement LWG3940: std::expected<void, E>::value() also needs E to be copy constructible #71819
Changes from all commits
3e4b73d
2d1c43f
0767b57
a5ea305
cc85707
7d6b115
5cf3dc6
0404b8d
4ef228b
8f558c5
2614080
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//===----------------------------------------------------------------------===// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 | ||
// UNSUPPORTED: no-rtti | ||
// UNSUPPORTED: no-exceptions | ||
|
||
// constexpr void value() const &; | ||
// Mandates: is_copy_constructible_v<E> is true. | ||
|
||
// constexpr void value() &&; | ||
// Mandates: is_copy_constructible_v<E> is true and is_move_constructible_v<E> is true. | ||
|
||
#include <expected> | ||
|
||
#include "MoveOnly.h" | ||
|
||
struct CopyOnly { | ||
CopyOnly() = default; | ||
CopyOnly(const CopyOnly&) = default; | ||
CopyOnly(CopyOnly&&) = delete; | ||
}; | ||
|
||
void test() { | ||
PragmaTwice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// MoveOnly type as error_type | ||
std::expected<void, MoveOnly> e(std::unexpect, 5); | ||
|
||
e.value(); // expected-note {{in instantiation of member function 'std::expected<void, MoveOnly>::value' requested here}} | ||
// expected-error@*:* {{static assertion failed due to requirement 'is_copy_constructible_v<MoveOnly>'}} | ||
// expected-error@*:* {{call to deleted constructor of 'MoveOnly'}} | ||
|
||
std::move(e) | ||
.value(); // expected-note {{in instantiation of member function 'std::expected<void, MoveOnly>::value' requested here}} | ||
// expected-error@*:* {{static assertion failed due to requirement 'is_copy_constructible_v<MoveOnly>'}} | ||
|
||
// CopyOnly type as error_type | ||
std::expected<void, CopyOnly> e2(std::unexpect); | ||
// expected-error@*:* {{call to deleted constructor of 'CopyOnly'}} | ||
|
||
e2.value(); | ||
|
||
std::move(e2) | ||
.value(); // expected-note {{in instantiation of member function 'std::expected<void, CopyOnly>::value' requested here}} | ||
// expected-error@*:* {{static assertion failed due to requirement 'is_move_constructible_v<CopyOnly>'}} | ||
// expected-error@*:* {{call to deleted constructor of 'CopyOnly'}} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,17 +65,6 @@ void testException() { | |
} | ||
} | ||
|
||
// MoveOnly | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of interest, according to the LWG issue, this test should never work. Do you know why there was not an issue before? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah due to LWG3940 it cannot pass the compiler. But I guess before this the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is because of Clang's non-conforming acception of move-only exception types, which is reported as #53224. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would this extension be non-conforming? A warning is missing, but other than that I don't see how it wouldn't be conforming. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that |
||
{ | ||
std::expected<void, MoveOnly> e(std::unexpect, 5); | ||
try { | ||
std::move(e).value(); | ||
assert(false); | ||
} catch (const std::bad_expected_access<MoveOnly>& ex) { | ||
assert(ex.error() == 5); | ||
} | ||
} | ||
|
||
#endif // TEST_HAS_NO_EXCEPTIONS | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.