From 794563c56afac91b7b2f3a9a7f13075d5bed70c2 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Mon, 5 Dec 2022 11:09:45 +0800 Subject: [PATCH 1/5] Test coverage for LWG-3746 --- tests/std/tests/P1614R2_spaceship/test.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/std/tests/P1614R2_spaceship/test.cpp b/tests/std/tests/P1614R2_spaceship/test.cpp index daeccca953..3b6dc63338 100644 --- a/tests/std/tests/P1614R2_spaceship/test.cpp +++ b/tests/std/tests/P1614R2_spaceship/test.cpp @@ -290,6 +290,9 @@ constexpr bool tuple_like_test() { return true; } +template +struct derived_optional : std::optional {}; + template constexpr bool optional_test() { using ReturnType = std::compare_three_way_result_t; @@ -313,6 +316,13 @@ constexpr bool optional_test() { assert(spaceship_test(o1, EqualVal, LargeVal)); } + { + constexpr std::optional o1(SmallVal); + constexpr derived_optional derived1{std::optional(SmallVal)}; + constexpr derived_optional derived2{std::optional(LargeVal)}; + + assert(spaceship_test(o1, derived1, derived2)); + } { constexpr std::optional o1(std::nullopt); constexpr std::optional o2(LargeVal); From 8e4c5e3d8c12310fc93822363f0f0d4c320d0cee Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Mon, 5 Dec 2022 11:10:49 +0800 Subject: [PATCH 2/5] Implement LWG-3746 --- stl/inc/optional | 2 +- stl/inc/xutility | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/stl/inc/optional b/stl/inc/optional index 6b88502722..a86eaa23be 100644 --- a/stl/inc/optional +++ b/stl/inc/optional @@ -926,7 +926,7 @@ _NODISCARD constexpr bool operator>=(const _Ty1& _Left, const optional<_Ty2>& _R #ifdef __cpp_lib_concepts // clang-format off _EXPORT_STD template - requires (!_Is_specialization_v<_Ty2, optional>) + requires (!_Derived_from_specialization_of<_Ty2, optional>) && three_way_comparable_with<_Ty1, _Ty2> _NODISCARD constexpr compare_three_way_result_t<_Ty1, _Ty2> operator<=>(const optional<_Ty1>& _Left, const _Ty2& _Right) diff --git a/stl/inc/xutility b/stl/inc/xutility index b8a210a37a..180845258f 100644 --- a/stl/inc/xutility +++ b/stl/inc/xutility @@ -400,6 +400,14 @@ using _Algorithm_int_t = conditional_t, _Ty, ptrdiff_t>; template concept _Destructible_object = is_object_v<_Ty> && destructible<_Ty>; +template