From 4bb58217d55829b5f53ec4e8cf2fc31371dc6a24 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 24 Mar 2023 00:58:15 +0800 Subject: [PATCH 1/6] Implement LWG-3836 for `optional` and add test coverage --- stl/inc/optional | 16 ++++++++++------ tests/std/tests/P0220R1_optional/test.cpp | 10 ++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/stl/inc/optional b/stl/inc/optional index a86eaa23be7..01269d4c114 100644 --- a/stl/inc/optional +++ b/stl/inc/optional @@ -239,7 +239,9 @@ public: template using _AllowDirectConversion = bool_constant, optional>>, - negation, in_place_t>>, is_constructible<_Ty, _Ty2>>>; + negation, in_place_t>>, + negation, bool>, _Is_specialization<_Remove_cvref_t<_Ty2>, optional>>>, + is_constructible<_Ty, _Ty2>>>; template ::value, int> = 0> constexpr explicit(!is_convertible_v<_Ty2, _Ty>) @@ -247,11 +249,13 @@ public: : _Mybase(in_place, _STD forward<_Ty2>(_Right)) {} template - struct _AllowUnwrapping : bool_constant, is_constructible<_Ty, optional<_Ty2>&>, - is_constructible<_Ty, const optional<_Ty2>&>, - is_constructible<_Ty, const optional<_Ty2>>, is_constructible<_Ty, optional<_Ty2>>, - is_convertible&, _Ty>, is_convertible&, _Ty>, - is_convertible, _Ty>, is_convertible, _Ty>>> {}; + struct _AllowUnwrapping + : bool_constant, bool>, + negation, is_constructible<_Ty, optional<_Ty2>&>, + is_constructible<_Ty, const optional<_Ty2>&>, is_constructible<_Ty, const optional<_Ty2>>, + is_constructible<_Ty, optional<_Ty2>>, is_convertible&, _Ty>, + is_convertible&, _Ty>, is_convertible, _Ty>, + is_convertible, _Ty>>>>> {}; template , is_constructible<_Ty, const _Ty2&>>, int> = 0> diff --git a/tests/std/tests/P0220R1_optional/test.cpp b/tests/std/tests/P0220R1_optional/test.cpp index 77d3497fde1..1b38f9228d4 100644 --- a/tests/std/tests/P0220R1_optional/test.cpp +++ b/tests/std/tests/P0220R1_optional/test.cpp @@ -8148,6 +8148,16 @@ namespace msvc { STATIC_ASSERT(!is_constructible_v); } // namespace lwg2842 + namespace lwg3836 { + STATIC_ASSERT(std::is_convertible_v, std::optional>); + STATIC_ASSERT(std::is_convertible_v&, std::optional>); + + constexpr std::optional oi = 0; + constexpr std::optional ob = oi; + STATIC_ASSERT(!ob.value()); + STATIC_ASSERT(!std::optional{std::optional{0}}.value()); + } // namespace lwg3836 + namespace vso406124 { // Defend against regression of VSO-406124 void run_test() { From 585e878b3da815e6d0e2815a4d41f4aaf0fee6c6 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 24 Mar 2023 01:11:18 +0800 Subject: [PATCH 2/6] Implement LWG-3836 for `expected` and add test coverage --- stl/inc/expected | 21 ++++++++++++--------- tests/std/tests/P0323R12_expected/test.cpp | 8 ++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/stl/inc/expected b/stl/inc/expected index a0f05bd8eea..93fbfcf0843 100644 --- a/stl/inc/expected +++ b/stl/inc/expected @@ -238,14 +238,15 @@ public: // clang-format on template - static constexpr bool _Allow_unwrapping = !is_constructible_v<_Ty, expected<_Uty, _UErr>&> // - && !is_constructible_v<_Ty, expected<_Uty, _UErr>> // - && !is_constructible_v<_Ty, const expected<_Uty, _UErr>&> // - && !is_constructible_v<_Ty, const expected<_Uty, _UErr>> // - && !is_convertible_v&, _Ty> // - && !is_convertible_v&&, _Ty> // - && !is_convertible_v&, _Ty> // - && !is_convertible_v&&, _Ty> // + static constexpr bool _Allow_unwrapping = disjunction_v, bool>, + negation&>, // + is_constructible<_Ty, expected<_Uty, _UErr>>, // + is_constructible<_Ty, const expected<_Uty, _UErr>&>, // + is_constructible<_Ty, const expected<_Uty, _UErr>>, // + is_convertible&, _Ty>, // + is_convertible&&, _Ty>, // + is_convertible&, _Ty>, // + is_convertible&&, _Ty>>>> // && !is_constructible_v, expected<_Uty, _UErr>&> // && !is_constructible_v, expected<_Uty, _UErr>> // && !is_constructible_v, const expected<_Uty, _UErr>&> // @@ -280,7 +281,9 @@ public: template requires (!is_same_v, in_place_t> && !is_same_v, expected> - && !_Is_specialization_v, unexpected> && is_constructible_v<_Ty, _Uty>) + && !_Is_specialization_v, unexpected> + && (!is_same_v, bool> || !_Is_specialization_v, expected>) + && is_constructible_v<_Ty, _Uty>) constexpr explicit(!is_convertible_v<_Uty, _Ty>) expected(_Uty&& _Other) noexcept(is_nothrow_constructible_v<_Ty, _Uty>) // strengthened : _Value(_STD forward<_Uty>(_Other)), _Has_value(true) {} diff --git a/tests/std/tests/P0323R12_expected/test.cpp b/tests/std/tests/P0323R12_expected/test.cpp index 14bfc85b158..546077a1ea5 100644 --- a/tests/std/tests/P0323R12_expected/test.cpp +++ b/tests/std/tests/P0323R12_expected/test.cpp @@ -662,6 +662,14 @@ namespace test_expected { test_constructors(); test_constructors(); test_constructors(); + + // LWG-3836 + struct BaseError {}; + struct DerivedError : BaseError {}; + + std::expected e1(false); + std::expected e2(e1); + assert(!e2.value()); } template Date: Fri, 24 Mar 2023 01:19:24 +0800 Subject: [PATCH 3/6] Missing clang-format --- tests/std/tests/P0220R1_optional/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P0220R1_optional/test.cpp b/tests/std/tests/P0220R1_optional/test.cpp index 1b38f9228d4..bae0e9f8378 100644 --- a/tests/std/tests/P0220R1_optional/test.cpp +++ b/tests/std/tests/P0220R1_optional/test.cpp @@ -8152,7 +8152,7 @@ namespace msvc { STATIC_ASSERT(std::is_convertible_v, std::optional>); STATIC_ASSERT(std::is_convertible_v&, std::optional>); - constexpr std::optional oi = 0; + constexpr std::optional oi = 0; constexpr std::optional ob = oi; STATIC_ASSERT(!ob.value()); STATIC_ASSERT(!std::optional{std::optional{0}}.value()); From ca824fa129f56561fb5dd7e0ce326b70ce704e69 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 24 Mar 2023 01:52:27 +0800 Subject: [PATCH 4/6] Fix `optional` test case for C++17 --- tests/std/tests/P0220R1_optional/test.cpp | 24 +++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/std/tests/P0220R1_optional/test.cpp b/tests/std/tests/P0220R1_optional/test.cpp index bae0e9f8378..dbadbcd0c3a 100644 --- a/tests/std/tests/P0220R1_optional/test.cpp +++ b/tests/std/tests/P0220R1_optional/test.cpp @@ -8152,10 +8152,24 @@ namespace msvc { STATIC_ASSERT(std::is_convertible_v, std::optional>); STATIC_ASSERT(std::is_convertible_v&, std::optional>); - constexpr std::optional oi = 0; - constexpr std::optional ob = oi; - STATIC_ASSERT(!ob.value()); - STATIC_ASSERT(!std::optional{std::optional{0}}.value()); +#if _HAS_CXX20 +#define CONSTEXPR20 constexpr +#else // ^^^ _HAS_CXX20 / _HAS_CXX20 vvv +#define CONSTEXPR20 inline +#endif // ^^^ _HAS_CXX20 ^^^ + CONSTEXPR20 bool run_test() { + std::optional oi = 0; + std::optional ob = oi; + assert(!ob.value()); + assert(!std::optional{std::optional{0}}.value()); + + return true; + } +#undef CONSTEXPR20 + +#if _HAS_CXX20 + STATIC_ASSERT(run_test()); +#endif // _HAS_CXX20 } // namespace lwg3836 namespace vso406124 { @@ -8344,6 +8358,8 @@ int main() { nonmembers::make_optional_explicit_init_list::run_test(); nonmembers::swap_::run_test(); + msvc::lwg3836::run_test(); + msvc::vso406124::run_test(); msvc::vso508126::run_test(); msvc::vso614907::run_test(); From 7e2e1cf975516560d7761e9ee7105475d908a093 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 24 Mar 2023 01:52:45 +0800 Subject: [PATCH 5/6] Skip one libc++ test --- tests/libcxx/expected_results.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/libcxx/expected_results.txt b/tests/libcxx/expected_results.txt index 2d41f7f11b8..cdd96775d45 100644 --- a/tests/libcxx/expected_results.txt +++ b/tests/libcxx/expected_results.txt @@ -120,6 +120,9 @@ std/language.support/support.limits/support.limits.general/format.version.compil # libc++ doesn't implement LWG-3670 std/ranges/range.factories/range.iota.view/iterator/member_typedefs.compile.pass.cpp FAIL +# libc++ doesn't implement LWG-3836 +std/utilities/expected/expected.expected/ctor/ctor.u.pass.cpp FAIL + # libc++ doesn't implement LWG-3857 std/strings/string.view/string.view.cons/from_range.pass.cpp FAIL std/strings/string.view/string.view.cons/from_string1.compile.fail.cpp FAIL From 92a86f00ab0f383296f6512aefcb3236eef8a335 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 24 Mar 2023 01:55:11 +0800 Subject: [PATCH 6/6] Fix copy-pasta --- tests/std/tests/P0220R1_optional/test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/std/tests/P0220R1_optional/test.cpp b/tests/std/tests/P0220R1_optional/test.cpp index dbadbcd0c3a..aee3c2a6f34 100644 --- a/tests/std/tests/P0220R1_optional/test.cpp +++ b/tests/std/tests/P0220R1_optional/test.cpp @@ -8154,9 +8154,9 @@ namespace msvc { #if _HAS_CXX20 #define CONSTEXPR20 constexpr -#else // ^^^ _HAS_CXX20 / _HAS_CXX20 vvv +#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv #define CONSTEXPR20 inline -#endif // ^^^ _HAS_CXX20 ^^^ +#endif // ^^^ !_HAS_CXX20 ^^^ CONSTEXPR20 bool run_test() { std::optional oi = 0; std::optional ob = oi;