]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Improve optional's <=> constraint recursion workaround [PR104606]
authorPatrick Palka <ppalka@redhat.com>
Fri, 28 Feb 2025 15:15:45 +0000 (10:15 -0500)
committerPatrick Palka <ppalka@redhat.com>
Tue, 29 Apr 2025 01:37:48 +0000 (21:37 -0400)
It turns out the reason the behavior of this testcase changed after CWG
2369 is because validity of the substituted return type is now checked
later, after constraints.  So a more reliable workaround for this issue
is to add a constraint to check the validity of the return type earlier,
matching the pre-CWG 2369 semantics.

PR libstdc++/104606

libstdc++-v3/ChangeLog:

* include/std/optional (operator<=>): Revert r14-9771 change.
Add constraint checking the validity of the return type
compare_three_way_result_t before the three_way_comparable_with
constraint.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
(cherry picked from commit 815f1f27a1dba2f0acd1f02d0beafedadebe967c)

libstdc++-v3/include/std/optional

index 3507c36a4d826d12edc12b9f4c874656a576f128..1c37c8c5ac81dab0197b4b2eb44ac15ca37e914d 100644 (file)
@@ -1430,7 +1430,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #ifdef __cpp_lib_three_way_comparison
   template<typename _Tp, typename _Up>
     requires (!__is_optional_v<_Up>)
-      && three_way_comparable_with<_Up, _Tp>
+      && requires { typename compare_three_way_result_t<_Tp, _Up>; }
+      && three_way_comparable_with<_Tp, _Up>
     constexpr compare_three_way_result_t<_Tp, _Up>
     operator<=>(const optional<_Tp>& __x, const _Up& __v)
     { return bool(__x) ? *__x <=> __v : strong_ordering::less; }