From 90fca2789761edfc587d4d75c9999d4ad0b11662 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Sat, 13 Jul 2024 14:40:38 +0800 Subject: [PATCH 1/2] Add deleted overloads to `expected` --- stl/inc/expected | 8 ++++ tests/std/tests/P0323R12_expected/test.cpp | 45 ++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/stl/inc/expected b/stl/inc/expected index aad81b7007e..fd82ba69ac1 100644 --- a/stl/inc/expected +++ b/stl/inc/expected @@ -258,6 +258,8 @@ public: is_trivially_copy_constructible_v<_Ty> && is_trivially_copy_constructible_v<_Err> = default; // clang-format on + expected(const expected&) = delete; + constexpr expected(expected&& _Other) noexcept( is_nothrow_move_constructible_v<_Ty> && is_nothrow_move_constructible_v<_Err>) requires (!(is_trivially_move_constructible_v<_Ty> && is_trivially_move_constructible_v<_Err>) @@ -441,6 +443,8 @@ public: && _Trivially_copy_constructible_assignable_destructible<_Err> = default; + expected& operator=(const expected&) = delete; + constexpr expected& operator=(expected&& _Other) noexcept( is_nothrow_move_constructible_v<_Ty> && is_nothrow_move_constructible_v<_Err> && is_nothrow_move_assignable_v<_Ty> && is_nothrow_move_assignable_v<_Err>) @@ -1243,6 +1247,8 @@ public: expected(const expected&) requires is_trivially_copy_constructible_v<_Err> = default; // clang-format on + expected(const expected&) = delete; + constexpr expected(expected&& _Other) noexcept(is_nothrow_move_constructible_v<_Err>) requires (!is_trivially_move_constructible_v<_Err> && is_move_constructible_v<_Err>) : _Has_value(_Other._Has_value) { @@ -1344,6 +1350,8 @@ public: requires _Expected_unary_copy_assignable<_Err> && _Trivially_copy_constructible_assignable_destructible<_Err> = default; + expected& operator=(const expected&) = delete; + constexpr expected& operator=(expected&& _Other) noexcept( is_nothrow_move_constructible_v<_Err> && is_nothrow_move_assignable_v<_Err>) requires _Expected_unary_move_assignable<_Err> diff --git a/tests/std/tests/P0323R12_expected/test.cpp b/tests/std/tests/P0323R12_expected/test.cpp index e5cc5cc35d2..3e678eb8fc1 100644 --- a/tests/std/tests/P0323R12_expected/test.cpp +++ b/tests/std/tests/P0323R12_expected/test.cpp @@ -2343,6 +2343,51 @@ constexpr bool test_inherited_constructors() { static_assert(test_inherited_constructors()); +// Test GH-4279 "Add deleted function overloads to expected" + +template +struct ambiguating_expected_copy_constructor_caller { + struct const_lvalue_taker { + const_lvalue_taker(const expected&) {} + }; + + void operator()(expected) {} + void operator()(const_lvalue_taker) {} +}; + +template +struct ambiguating_expected_assignment_source { + operator const expected&() && { + return ex; + } + + operator expected&&() && { + return move(ex); + } + + expected ex; +}; + +struct move_only { + move_only() = default; + move_only(move_only&&) = default; + move_only& operator=(move_only&&) = default; +}; + +static_assert(is_invocable_v, const expected&>); +static_assert(is_invocable_v, const expected&>); +static_assert( + !is_invocable_v, const expected&>); +static_assert( + !is_invocable_v, const expected&>); + +#ifndef __EDG__ // TRANSITION, VSO-1601179 +static_assert(!is_assignable_v&, ambiguating_expected_assignment_source>); +static_assert(!is_assignable_v&, ambiguating_expected_assignment_source>); +#endif // ^^^ no workaround ^^^ +static_assert(!is_assignable_v&, ambiguating_expected_assignment_source>); +static_assert(!is_assignable_v&, ambiguating_expected_assignment_source>); + int main() { test_unexpected::test_all(); static_assert(test_unexpected::test_all()); From e5afb0b733b796457528816f3f50e0464d2cf14f Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 6 Aug 2024 13:11:05 -0700 Subject: [PATCH 2/2] Work around VSO-2188364 "EDG assertion failed in conversion_for_direct_reference_binding_possible". --- tests/std/tests/P0323R12_expected/test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/std/tests/P0323R12_expected/test.cpp b/tests/std/tests/P0323R12_expected/test.cpp index 3e678eb8fc1..1c97c0092c3 100644 --- a/tests/std/tests/P0323R12_expected/test.cpp +++ b/tests/std/tests/P0323R12_expected/test.cpp @@ -2385,8 +2385,10 @@ static_assert( static_assert(!is_assignable_v&, ambiguating_expected_assignment_source>); static_assert(!is_assignable_v&, ambiguating_expected_assignment_source>); #endif // ^^^ no workaround ^^^ +#ifndef __EDG__ // TRANSITION, VSO-2188364 static_assert(!is_assignable_v&, ambiguating_expected_assignment_source>); static_assert(!is_assignable_v&, ambiguating_expected_assignment_source>); +#endif // ^^^ no workaround ^^^ int main() { test_unexpected::test_all();