libstdc++: Add compare_three_way and install <compare> header
authorJonathan Wakely <jwakely@redhat.com>
Wed, 6 Nov 2019 17:53:38 +0000 (17:53 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 6 Nov 2019 17:53:38 +0000 (17:53 +0000)
* include/Makefile.in: Regenerate.
* libsupc++/Makefile.in: Regenerate.
* libsupc++/compare (__3way_builtin_ptr_cmp): Define helper.
(compare_three_way): Add missing implementation.

From-SVN: r277889

libstdc++-v3/ChangeLog
libstdc++-v3/include/Makefile.in
libstdc++-v3/libsupc++/Makefile.in
libstdc++-v3/libsupc++/compare

index 5dece5c9eb5c5045a0e2f511d629042d4bd8ad82..3eb20181139e70fe445b2a597b29924f2f59b4f7 100644 (file)
@@ -1,5 +1,10 @@
 2019-11-06  Jonathan Wakely  <jwakely@redhat.com>
 
+       * include/Makefile.in: Regenerate.
+       * libsupc++/Makefile.in: Regenerate.
+       * libsupc++/compare (__3way_builtin_ptr_cmp): Define helper.
+       (compare_three_way): Add missing implementation.
+
        * include/bits/iterator_concepts.h (unreachable_sentinel_t): Remove
        redundant equality operators.
        * testsuite/util/testsuite_iterators.h (test_range::sentinel):
index d9eb306a21340ba50a4b4c986462bece544493eb..acc4fe5f4c969ac2e50d534636ab92e420fc0ed7 100644 (file)
@@ -1859,8 +1859,9 @@ ${pch3_output}: ${pch3_source} ${pch2_output}
 # <new>, <typeinfo>, <exception>, <initializer_list>, <cstdalign>, <cstdarg>,
 # <concepts>, <cstdbool>, <type_traits>, <bit>, <atomic>,
 # and any files which they include (and which we provide).
-# <new>, <typeinfo>, <exception>, and <initializer_list> are installed by
-# libsupc++, so only the others and the sub-includes are copied here.
+# <new>, <typeinfo>, <exception>, <initializer_list> and <compare>
+# are installed by libsupc++, so only the others and the sub-includes
+# are copied here.
 install-freestanding-headers:
        $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/bits
        for file in c++0x_warning.h atomic_base.h concept_check.h move.h; do \
index 5d8ac5ca0ba0deec8da8c25f61f40ac4957b82f9..38e34cbb516427df33185d4f430e67ecab586e7f 100644 (file)
@@ -483,7 +483,7 @@ toolexeclib_LTLIBRARIES = libsupc++.la
 # 2) integrated libsupc++convenience.la that is to be a part of libstdc++.a
 noinst_LTLIBRARIES = libsupc++convenience.la
 std_HEADERS = \
-       cxxabi.h exception initializer_list new typeinfo
+       compare cxxabi.h exception initializer_list new typeinfo
 
 bits_HEADERS = \
        atomic_lockfree_defines.h cxxabi_forced.h \
index 379b2d485827a25703556c2a5812051c02e31d24..2e518ccbffde70493dca489d508deb37c2f79aa9 100644 (file)
@@ -519,7 +519,8 @@ namespace std
 
   // [cmp.common], common comparison category type
   template<typename... _Ts>
-    struct common_comparison_category {
+    struct common_comparison_category
+    {
       // using type = TODO
     };
 
@@ -527,7 +528,7 @@ namespace std
     using common_comparison_category_t
       = typename common_comparison_category<_Ts...>::type;
 
-#if __cpp_concepts
+#if __cpp_lib_concepts
   namespace __detail
   {
     template<typename _Tp, typename _Cat>
@@ -604,20 +605,42 @@ namespace std
     using compare_three_way_result_t
       = typename compare_three_way_result<_Tp, _Up>::__type;
 
+#if __cpp_lib_concepts
+  namespace __detail
+  {
+    // BUILTIN-PTR-THREE-WAY(T, U)
+    template<typename _Tp, typename _Up>
+      concept __3way_builtin_ptr_cmp
+       = convertible_to<_Tp, const volatile void*>
+         && convertible_to<_Up, const volatile void*>
+         && ! requires(_Tp&& __t, _Up&& __u)
+            { operator<=>(static_cast<_Tp&&>(__t), static_cast<_Up&&>(__u)); }
+         && ! requires(_Tp&& __t, _Up&& __u)
+            { static_cast<_Tp&&>(__t).operator<=>(static_cast<_Up&&>(__u)); };
+  } // namespace __detail
+
   // [cmp.object], typename compare_three_way
   struct compare_three_way
   {
-    // TODO
-#if 0
     template<typename _Tp, typename _Up>
       requires (three_way_comparable_with<_Tp, _Up>
-         || BUILTIN-PTR-THREE-WAY(_Tp, _Up))
+         || __detail::__3way_builtin_ptr_cmp<_Tp, _Up>)
     constexpr auto
     operator()(_Tp&& __t, _Up&& __u) const noexcept
     {
-      // TODO
+      if constexpr (__detail::__3way_builtin_ptr_cmp<_Tp, _Up>)
+       {
+         auto __pt = static_cast<const volatile void*>(__t);
+         auto __pu = static_cast<const volatile void*>(__u);
+         if (__builtin_is_constant_evaluated())
+           return __pt <=> __pu;
+         auto __it = reinterpret_cast<__UINTPTR_TYPE__>(__pt);
+         auto __iu = reinterpret_cast<__UINTPTR_TYPE__>(__pu);
+         return __it <=> __iu;
+       }
+      else
+       return static_cast<_Tp&&>(__t) <=> static_cast<_Up&&>(__u);
     }
-#endif
 
     using is_transparent = void;
   };
@@ -635,7 +658,8 @@ namespace std
     inline constexpr unspecified compare_partial_order_fallback = unspecified;
 #endif
   }
-}
+#endif
+} // namespace std
 
 #pragma GCC visibility pop