public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed 1/2] libstdc++: Change [cmp.alg] assertions to constraints
@ 2021-06-14 13:07 Jonathan Wakely
  2021-06-14 13:08 ` [committed 2/2] libstdc++: Implement LWG 3465 for std::compare_partial_order_fallback [PR101056] Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Wakely @ 2021-06-14 13:07 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 665 bytes --]

This moves the same_as<decay_t<_Tp>, decay_t<_Up>> checks from the
[cmp.alg] function bodies into their constraints.

Also add a test for the compare_xxx_order_fallback algorithms.

libstdc++-v3/ChangeLog:

	* libsupc++/compare (__decayed_same_as): New helper concept.
	(strong_order, weak_order, partial_order): Constrain with new
	concept instead of using static_assert.
	(compare_strong_order_fallback, compare_weak_order_fallback)
	(compare_partial_order_fallback): Likewise. Do not deduce return
	types. Remove redundant if-constexpr checks.
	* testsuite/18_support/comparisons/algorithms/fallback.cc: New test.

Tested powerpc64le-linux. Committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 7037 bytes --]

commit e2c79b968ff95421c31a5a9a1b80b11321fe70d2
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Jun 14 12:25:43 2021

    libstdc++: Change [cmp.alg] assertions to constraints
    
    This moves the same_as<decay_t<_Tp>, decay_t<_Up>> checks from the
    [cmp.alg] function bodies into their constraints.
    
    Also add a test for the compare_xxx_order_fallback algorithms.
    
    libstdc++-v3/ChangeLog:
    
            * libsupc++/compare (__decayed_same_as): New helper concept.
            (strong_order, weak_order, partial_order): Constrain with new
            concept instead of using static_assert.
            (compare_strong_order_fallback, compare_weak_order_fallback)
            (compare_partial_order_fallback): Likewise. Do not deduce return
            types. Remove redundant if-constexpr checks.
            * testsuite/18_support/comparisons/algorithms/fallback.cc: New test.

diff --git a/libstdc++-v3/libsupc++/compare b/libstdc++-v3/libsupc++/compare
index 82d00889272..b1f342113f1 100644
--- a/libstdc++-v3/libsupc++/compare
+++ b/libstdc++-v3/libsupc++/compare
@@ -600,6 +600,9 @@ namespace std
 	  // FIXME: || floating_point<remove_reference_t<_Tp>>
 	  || __cmp3way<strong_ordering, _Tp, _Up>;
 
+    template<typename _Tp, typename _Up>
+      concept __decayed_same_as = same_as<decay_t<_Tp>, decay_t<_Up>>;
+
     class _Strong_order
     {
       template<typename _Tp, typename _Up>
@@ -620,14 +623,12 @@ namespace std
       friend class _Strong_fallback;
 
     public:
-      template<typename _Tp, typename _Up>
+      template<typename _Tp, __decayed_same_as<_Tp> _Up>
 	requires __strongly_ordered<_Tp, _Up>
 	constexpr strong_ordering
 	operator()(_Tp&& __e, _Up&& __f) const
 	noexcept(_S_noexcept<_Tp, _Up>())
 	{
-	  static_assert(same_as<decay_t<_Tp>, decay_t<_Up>>);
-
 	  /* FIXME:
 	  if constexpr (floating_point<decay_t<_Tp>>)
 	    return __cmp_cust::__fp_strong_order(__e, __f);
@@ -669,14 +670,12 @@ namespace std
       friend class _Weak_fallback;
 
     public:
-      template<typename _Tp, typename _Up>
+      template<typename _Tp, __decayed_same_as<_Tp> _Up>
 	requires __weakly_ordered<_Tp, _Up>
 	constexpr weak_ordering
 	operator()(_Tp&& __e, _Up&& __f) const
 	noexcept(_S_noexcept<_Tp, _Up>())
 	{
-	  static_assert(same_as<decay_t<_Tp>, decay_t<_Up>>);
-
 	  if constexpr (floating_point<decay_t<_Tp>>)
 	    return __cmp_cust::__fp_weak_ordering(__e, __f);
 	  else if constexpr (__adl_weak<_Tp, _Up>)
@@ -716,14 +715,12 @@ namespace std
       friend class _Partial_fallback;
 
     public:
-      template<typename _Tp, typename _Up>
+      template<typename _Tp, __decayed_same_as<_Tp> _Up>
 	requires __partially_ordered<_Tp, _Up>
 	constexpr partial_ordering
 	operator()(_Tp&& __e, _Up&& __f) const
 	noexcept(_S_noexcept<_Tp, _Up>())
 	{
-	  static_assert(same_as<decay_t<_Tp>, decay_t<_Up>>);
-
 	  if constexpr (__adl_partial<_Tp, _Up>)
 	    return partial_ordering(partial_order(static_cast<_Tp&&>(__e),
 						  static_cast<_Up&&>(__f)));
@@ -759,18 +756,16 @@ namespace std
 	}
 
     public:
-      template<typename _Tp, typename _Up>
+      template<typename _Tp, __decayed_same_as<_Tp> _Up>
 	requires __strongly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up>
-	constexpr decltype(auto)
+	constexpr strong_ordering
 	operator()(_Tp&& __e, _Up&& __f) const
 	noexcept(_S_noexcept<_Tp, _Up>())
 	{
-	  static_assert(same_as<decay_t<_Tp>, decay_t<_Up>>);
-
 	  if constexpr (__strongly_ordered<_Tp, _Up>)
 	    return _Strong_order{}(static_cast<_Tp&&>(__e),
 				   static_cast<_Up&&>(__f));
-	  else if constexpr (__op_eq_lt<_Tp, _Up>)
+	  else // __op_eq_lt<_Tp, _Up>
 	    return static_cast<_Tp&&>(__e) == static_cast<_Up&&>(__f)
 	      ? strong_ordering::equal
 	      : static_cast<_Tp&&>(__e) < static_cast<_Up&&>(__f)
@@ -793,18 +788,16 @@ namespace std
 	}
 
     public:
-      template<typename _Tp, typename _Up>
+      template<typename _Tp, __decayed_same_as<_Tp> _Up>
 	requires __weakly_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up>
-	constexpr decltype(auto)
+	constexpr weak_ordering
 	operator()(_Tp&& __e, _Up&& __f) const
 	noexcept(_S_noexcept<_Tp, _Up>())
 	{
-	  static_assert(same_as<decay_t<_Tp>, decay_t<_Up>>);
-
 	  if constexpr (__weakly_ordered<_Tp, _Up>)
 	    return _Weak_order{}(static_cast<_Tp&&>(__e),
 				 static_cast<_Up&&>(__f));
-	  else if constexpr (__op_eq_lt<_Tp, _Up>)
+	  else // __op_eq_lt<_Tp, _Up>
 	    return static_cast<_Tp&&>(__e) == static_cast<_Up&&>(__f)
 	      ? weak_ordering::equivalent
 	      : static_cast<_Tp&&>(__e) < static_cast<_Up&&>(__f)
@@ -827,18 +820,16 @@ namespace std
 	}
 
     public:
-      template<typename _Tp, typename _Up>
+      template<typename _Tp, __decayed_same_as<_Tp> _Up>
 	requires __partially_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up>
-	constexpr decltype(auto)
+	constexpr partial_ordering
 	operator()(_Tp&& __e, _Up&& __f) const
 	noexcept(_S_noexcept<_Tp, _Up>())
 	{
-	  static_assert(same_as<decay_t<_Tp>, decay_t<_Up>>);
-
 	  if constexpr (__partially_ordered<_Tp, _Up>)
 	    return _Partial_order{}(static_cast<_Tp&&>(__e),
 				    static_cast<_Up&&>(__f));
-	  else if constexpr (__op_eq_lt<_Tp, _Up>)
+	  else // __op_eq_lt<_Tp, _Up>
 	    return static_cast<_Tp&&>(__e) == static_cast<_Up&&>(__f)
 	      ? partial_ordering::equivalent
 	      : static_cast<_Tp&&>(__e) < static_cast<_Up&&>(__f)
diff --git a/libstdc++-v3/testsuite/18_support/comparisons/algorithms/fallback.cc b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/fallback.cc
new file mode 100644
index 00000000000..ae458528f17
--- /dev/null
+++ b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/fallback.cc
@@ -0,0 +1,42 @@
+// { dg-options "-std=gnu++20" }
+// { dg-do compile { target c++20 } }
+
+#include <compare>
+
+using std::strong_ordering;
+using std::partial_ordering;
+
+namespace adl
+{
+  struct S { };
+  void strong_ordering(const S&, const S&);
+  bool operator==(const S&, S&) { return true; }
+  bool operator<(const S&, S&) { return true; }
+}
+
+template<typename T, typename U>
+  concept has_strong_order_fallback = requires (T& t, U& u) {
+    std::compare_strong_order_fallback(t, u);
+  };
+
+template<typename T, typename U>
+  concept has_weak_order_fallback = requires (T& t, U& u) {
+    std::compare_weak_order_fallback(t, u);
+  };
+
+template<typename T, typename U>
+  concept has_partial_order_fallback = requires (T& t, U& u) {
+    std::compare_partial_order_fallback(t, u);
+  };
+
+using adl::S;
+
+static_assert( has_strong_order_fallback<S, S> );
+static_assert( has_strong_order_fallback<const S, S> );
+static_assert( ! has_strong_order_fallback<const S, const S> );
+static_assert( has_weak_order_fallback<S, S> );
+static_assert( has_weak_order_fallback<const S, S> );
+static_assert( ! has_weak_order_fallback<const S, const S> );
+static_assert( has_partial_order_fallback<S, S> );
+static_assert( has_partial_order_fallback<const S, S> );
+static_assert( ! has_partial_order_fallback<const S, const S> );

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [committed 2/2] libstdc++: Implement LWG 3465 for std::compare_partial_order_fallback [PR101056]
  2021-06-14 13:07 [committed 1/2] libstdc++: Change [cmp.alg] assertions to constraints Jonathan Wakely
@ 2021-06-14 13:08 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2021-06-14 13:08 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 315 bytes --]

         PR libstdc++/101056
         * libsupc++/compare (compare_partial_order_fallback): Add
         constraint using reversed parameter order, as per LWG 3465.
         * testsuite/18_support/comparisons/algorithms/fallback.cc:
         Adjust expected result.

Tested powerpc64le-linux. Committed to trunk.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 2701 bytes --]

commit b76a529c095f076c4780df0c913cf6d2391bcbc9
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Jun 14 12:30:52 2021

    libstdc++: Implement LWG 3465 for std::compare_partial_order_fallback [PR101056]
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/101056
            * libsupc++/compare (compare_partial_order_fallback): Add
            constraint using reversed parameter order, as per LWG 3465.
            * testsuite/18_support/comparisons/algorithms/fallback.cc:
            Adjust expected result.

diff --git a/libstdc++-v3/libsupc++/compare b/libstdc++-v3/libsupc++/compare
index b1f342113f1..dd0ec5fa36d 100644
--- a/libstdc++-v3/libsupc++/compare
+++ b/libstdc++-v3/libsupc++/compare
@@ -806,6 +806,16 @@ namespace std
 	}
     };
 
+    // _GLIBCXX_RESOLVE_LIB_DEFECTS
+    // 3465. compare_partial_order_fallback requires F < E
+    template<typename _Tp, typename _Up>
+      concept __op_eq_lt_lt = __op_eq_lt<_Tp, _Up>
+	&& requires(_Tp&& __t, _Up&& __u)
+	{
+	  { static_cast<_Up&&>(__u) < static_cast<_Tp&&>(__t) }
+	    -> convertible_to<bool>;
+	};
+
     class _Partial_fallback
     {
       template<typename _Tp, typename _Up>
@@ -821,7 +831,7 @@ namespace std
 
     public:
       template<typename _Tp, __decayed_same_as<_Tp> _Up>
-	requires __partially_ordered<_Tp, _Up> || __op_eq_lt<_Tp, _Up>
+	requires __partially_ordered<_Tp, _Up> || __op_eq_lt_lt<_Tp, _Up>
 	constexpr partial_ordering
 	operator()(_Tp&& __e, _Up&& __f) const
 	noexcept(_S_noexcept<_Tp, _Up>())
@@ -829,7 +839,7 @@ namespace std
 	  if constexpr (__partially_ordered<_Tp, _Up>)
 	    return _Partial_order{}(static_cast<_Tp&&>(__e),
 				    static_cast<_Up&&>(__f));
-	  else // __op_eq_lt<_Tp, _Up>
+	  else // __op_eq_lt_lt<_Tp, _Up>
 	    return static_cast<_Tp&&>(__e) == static_cast<_Up&&>(__f)
 	      ? partial_ordering::equivalent
 	      : static_cast<_Tp&&>(__e) < static_cast<_Up&&>(__f)
diff --git a/libstdc++-v3/testsuite/18_support/comparisons/algorithms/fallback.cc b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/fallback.cc
index ae458528f17..05e1bf7775e 100644
--- a/libstdc++-v3/testsuite/18_support/comparisons/algorithms/fallback.cc
+++ b/libstdc++-v3/testsuite/18_support/comparisons/algorithms/fallback.cc
@@ -38,5 +38,5 @@ static_assert( has_weak_order_fallback<S, S> );
 static_assert( has_weak_order_fallback<const S, S> );
 static_assert( ! has_weak_order_fallback<const S, const S> );
 static_assert( has_partial_order_fallback<S, S> );
-static_assert( has_partial_order_fallback<const S, S> );
+static_assert( ! has_partial_order_fallback<const S, S> ); // LWG 3465
 static_assert( ! has_partial_order_fallback<const S, const S> );

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-14 13:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-14 13:07 [committed 1/2] libstdc++: Change [cmp.alg] assertions to constraints Jonathan Wakely
2021-06-14 13:08 ` [committed 2/2] libstdc++: Implement LWG 3465 for std::compare_partial_order_fallback [PR101056] Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).