libstdc++: Define <=> for Debug Mode array
authorJonathan Wakely <jwakely@redhat.com>
Thu, 27 Feb 2020 15:13:16 +0000 (15:13 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 27 Feb 2020 15:13:16 +0000 (15:13 +0000)
This fixes a test failure with -D_GLIBCXX_DEBUG:

FAIL: 23_containers/array/comparison_operators/constexpr.cc (test for excess errors)

* include/debug/array (operator<=>): Define for C++20.
* testsuite/23_containers/array/tuple_interface/get_debug_neg.cc:
Adjust dg-error line numbers.
* testsuite/23_containers/array/tuple_interface/
tuple_element_debug_neg.cc: Likewise.

libstdc++-v3/ChangeLog
libstdc++-v3/include/debug/array
libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_debug_neg.cc
libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_debug_neg.cc

index 05d6748..bd76b54 100644 (file)
@@ -1,5 +1,11 @@
 2020-02-27  Jonathan Wakely  <jwakely@redhat.com>
 
+       * include/debug/array (operator<=>): Define for C++20.
+       * testsuite/23_containers/array/tuple_interface/get_debug_neg.cc:
+       Adjust dg-error line numbers.
+       * testsuite/23_containers/array/tuple_interface/
+       tuple_element_debug_neg.cc: Likewise.
+
        * testsuite/23_containers/span/back_assert_neg.cc: Add #undef before
        defining _GLIBCXX_ASSERTIONS.
        * testsuite/23_containers/span/first_2_assert_neg.cc: Likewise.
index 3f87e98..dd4044c 100644 (file)
@@ -239,6 +239,25 @@ namespace __debug
     operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
     { return std::equal(__one.begin(), __one.end(), __two.begin()); }
 
+#if __cpp_lib_three_way_comparison && __cpp_lib_concepts
+  template<typename _Tp, size_t _Nm>
+    constexpr __detail::__synth3way_t<_Tp>
+    operator<=>(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)
+    {
+      if constexpr (_Nm && __is_byte<_Tp>::__value)
+       return __builtin_memcmp(__a.data(), __b.data(), _Nm) <=> 0;
+      else
+       {
+         for (size_t __i = 0; __i < _Nm; ++__i)
+           {
+             auto __c = __detail::__synth3way(__a[__i], __b[__i]);
+             if (__c != 0)
+               return __c;
+           }
+       }
+      return strong_ordering::equal;
+    }
+#else
   template<typename _Tp, std::size_t _Nm>
     _GLIBCXX20_CONSTEXPR
     inline bool
@@ -271,6 +290,7 @@ namespace __debug
     inline bool
     operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
     { return !(__one < __two); }
+#endif // three_way_comparison && concepts
 
   // Specialized algorithms.
 
index 2736d06..0a9525e 100644 (file)
@@ -27,6 +27,6 @@ int n1 = std::get<1>(a);
 int n2 = std::get<1>(std::move(a));
 int n3 = std::get<1>(ca);
 
-// { dg-error "static assertion failed" "" { target *-*-* } 295 }
-// { dg-error "static assertion failed" "" { target *-*-* } 304 }
-// { dg-error "static assertion failed" "" { target *-*-* } 312 }
+// { dg-error "static assertion failed" "" { target *-*-* } 315 }
+// { dg-error "static assertion failed" "" { target *-*-* } 324 }
+// { dg-error "static assertion failed" "" { target *-*-* } 332 }
index bca290b..0bd5989 100644 (file)
@@ -22,4 +22,4 @@
 
 typedef std::tuple_element<1, std::array<int, 1>>::type type;
 
-// { dg-error "static assertion failed" "" { target *-*-* } 377 }
+// { dg-error "static assertion failed" "" { target *-*-* } 397 }