[libcxx-commits] [libcxx] 9c0efc8 - [libc++] Module fixes for __synth_three_way.

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 7 09:54:16 PDT 2023


Author: Mark de Wever
Date: 2023-04-07T18:54:09+02:00
New Revision: 9c0efc8a0384df5bd0926e1ee946410cc95962ef

URL: https://github.com/llvm/llvm-project/commit/9c0efc8a0384df5bd0926e1ee946410cc95962ef
DIFF: https://github.com/llvm/llvm-project/commit/9c0efc8a0384df5bd0926e1ee946410cc95962ef.diff

LOG: [libc++] Module fixes for __synth_three_way.

These changes make it possible to use __synth_three_way in modules. The
change from a lambda to a function is a Clang issue.

The change is list was needed since the compiler couldn't deduce the
comparison template argument.

Adds a few missing includes too.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D146545

Added: 
    

Modified: 
    libcxx/include/__compare/synth_three_way.h
    libcxx/include/compare
    libcxx/include/deque
    libcxx/include/forward_list
    libcxx/include/list
    libcxx/include/map
    libcxx/utils/data/ignore_format.txt

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__compare/synth_three_way.h b/libcxx/include/__compare/synth_three_way.h
index f95832487c0ee..6420d1362db0c 100644
--- a/libcxx/include/__compare/synth_three_way.h
+++ b/libcxx/include/__compare/synth_three_way.h
@@ -25,21 +25,27 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 // [expos.only.func]
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way =
-  []<class _Tp, class _Up>(const _Tp& __t, const _Up& __u)
-    requires requires {
-      { __t < __u } -> __boolean_testable;
-      { __u < __t } -> __boolean_testable;
-    }
-  {
-    if constexpr (three_way_comparable_with<_Tp, _Up>) {
-      return __t <=> __u;
-    } else {
-      if (__t < __u) return weak_ordering::less;
-      if (__u < __t) return weak_ordering::greater;
-      return weak_ordering::equivalent;
-    }
-  };
+// TODO MODULES restore the lamba to match the Standard.
+// See https://github.com/llvm/llvm-project/issues/57222
+//_LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way =
+//  []<class _Tp, class _Up>(const _Tp& __t, const _Up& __u)
+template <class _Tp, class _Up>
+_LIBCPP_HIDE_FROM_ABI constexpr auto __synth_three_way(const _Tp& __t, const _Up& __u)
+  requires requires {
+    { __t < __u } -> __boolean_testable;
+    { __u < __t } -> __boolean_testable;
+  }
+{
+  if constexpr (three_way_comparable_with<_Tp, _Up>) {
+    return __t <=> __u;
+  } else {
+    if (__t < __u)
+      return weak_ordering::less;
+    if (__u < __t)
+      return weak_ordering::greater;
+    return weak_ordering::equivalent;
+  }
+}
 
 template <class _Tp, class _Up = _Tp>
 using __synth_three_way_result = decltype(std::__synth_three_way(std::declval<_Tp&>(), std::declval<_Up&>()));

diff  --git a/libcxx/include/compare b/libcxx/include/compare
index 9272dbf62b14c..626c7435f5fd0 100644
--- a/libcxx/include/compare
+++ b/libcxx/include/compare
@@ -151,6 +151,7 @@ namespace std {
 #include <__compare/ordering.h>
 #include <__compare/partial_order.h>
 #include <__compare/strong_order.h>
+#include <__compare/synth_three_way.h>
 #include <__compare/three_way_comparable.h>
 #include <__compare/weak_order.h>
 #include <__config>

diff  --git a/libcxx/include/deque b/libcxx/include/deque
index 166a75c843fd1..0f896bb231227 100644
--- a/libcxx/include/deque
+++ b/libcxx/include/deque
@@ -2399,7 +2399,7 @@ __synth_three_way_result<_Tp>
 operator<=>(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
 {
     return std::lexicographical_compare_three_way(
-        __x.begin(), __x.end(), __y.begin(), __y.end(), __synth_three_way);
+        __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Tp, _Tp>);
 }
 
 #endif // _LIBCPP_STD_VER <= 17

diff  --git a/libcxx/include/forward_list b/libcxx/include/forward_list
index e487d17919fad..e22968d49ed81 100644
--- a/libcxx/include/forward_list
+++ b/libcxx/include/forward_list
@@ -1775,7 +1775,7 @@ operator<=>(const forward_list<_Tp, _Allocator>& __x,
             const forward_list<_Tp, _Allocator>& __y)
 {
     return std::lexicographical_compare_three_way(
-        __x.begin(), __x.end(), __y.begin(), __y.end(), __synth_three_way);
+        __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Tp, _Tp>);
 }
 
 #endif // #if _LIBCPP_STD_VER <= 17

diff  --git a/libcxx/include/list b/libcxx/include/list
index 191f317341660..f925f542d41be 100644
--- a/libcxx/include/list
+++ b/libcxx/include/list
@@ -2349,7 +2349,7 @@ __synth_three_way_result<_Tp>
 operator<=>(const list<_Tp, _Allocator>& __x, const list<_Tp, _Allocator>& __y)
 {
     return std::lexicographical_compare_three_way(
-        __x.begin(), __x.end(), __y.begin(), __y.end(), __synth_three_way);
+        __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Tp, _Tp>);
 }
 
 #endif // _LIBCPP_STD_VER <= 17

diff  --git a/libcxx/include/map b/libcxx/include/map
index 98ee961559e27..9fbb5332a428a 100644
--- a/libcxx/include/map
+++ b/libcxx/include/map
@@ -1744,7 +1744,11 @@ operator<=>(const map<_Key, _Tp, _Compare, _Allocator>& __x,
             const map<_Key, _Tp, _Compare, _Allocator>& __y)
 {
     return std::lexicographical_compare_three_way(
-        __x.begin(), __x.end(), __y.begin(), __y.end(), __synth_three_way);
+        __x.begin(),
+        __x.end(),
+        __y.begin(),
+        __y.end(),
+        std::__synth_three_way<pair<const _Key, _Tp>, pair<const _Key, _Tp>>);
 }
 
 #endif // #if _LIBCPP_STD_VER <= 17
@@ -2354,7 +2358,11 @@ operator<=>(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
             const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
 {
     return std::lexicographical_compare_three_way(
-        __x.begin(), __x.end(), __y.begin(), __y.end(), __synth_three_way);
+        __x.begin(),
+        __x.end(),
+        __y.begin(),
+        __y.end(),
+        std::__synth_three_way<pair<const _Key, _Tp>, pair<const _Key, _Tp>>);
 }
 
 #endif // #if _LIBCPP_STD_VER <= 17

diff  --git a/libcxx/utils/data/ignore_format.txt b/libcxx/utils/data/ignore_format.txt
index a89361cbebc6a..62f997eee2cae 100644
--- a/libcxx/utils/data/ignore_format.txt
+++ b/libcxx/utils/data/ignore_format.txt
@@ -271,7 +271,6 @@ libcxx/include/__compare/compare_weak_order_fallback.h
 libcxx/include/__compare/ordering.h
 libcxx/include/__compare/partial_order.h
 libcxx/include/__compare/strong_order.h
-libcxx/include/__compare/synth_three_way.h
 libcxx/include/__compare/three_way_comparable.h
 libcxx/include/__compare/weak_order.h
 libcxx/include/complex


        


More information about the libcxx-commits mailing list