From: Jonathan Wakely Date: Thu, 27 Feb 2020 15:13:16 +0000 (+0000) Subject: libstdc++: Define <=> for Debug Mode array X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ae7051590d4bf9b844874e727791f236315c835a;p=gcc.git libstdc++: Define <=> for Debug Mode array 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. --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 05d6748ba51..bd76b541e8f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,11 @@ 2020-02-27 Jonathan Wakely + * 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. diff --git a/libstdc++-v3/include/debug/array b/libstdc++-v3/include/debug/array index 3f87e98fe8d..dd4044c9c7b 100644 --- a/libstdc++-v3/include/debug/array +++ b/libstdc++-v3/include/debug/array @@ -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 + 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 _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. diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_debug_neg.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_debug_neg.cc index 2736d060aed..0a9525e9654 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_debug_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_debug_neg.cc @@ -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 } diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_debug_neg.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_debug_neg.cc index bca290b3625..0bd5989c04a 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_debug_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_debug_neg.cc @@ -22,4 +22,4 @@ typedef std::tuple_element<1, std::array>::type type; -// { dg-error "static assertion failed" "" { target *-*-* } 377 } +// { dg-error "static assertion failed" "" { target *-*-* } 397 }