From ae7051590d4bf9b844874e727791f236315c835a Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 27 Feb 2020 15:13:16 +0000 Subject: [PATCH] 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. --- libstdc++-v3/ChangeLog | 6 ++++++ libstdc++-v3/include/debug/array | 20 ++++++++++++++++++++ .../array/tuple_interface/get_debug_neg.cc | 6 +++--- .../array/tuple_interface/tuple_element_debug_neg.cc | 2 +- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 05d6748..bd76b54 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 3f87e98..dd4044c 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 2736d06..0a9525e 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 bca290b..0bd5989 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 } -- 2.7.4