From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 291053858037; Tue, 16 Nov 2021 22:48:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 291053858037 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-5326] libstdc++: Fix tests for constexpr std::string X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 395848255cfa88f6f0f33a9b14c79e584a05d6fc X-Git-Newrev: 73e4d9f1751fd6d3c182988b2f9d0199c86053c9 Message-Id: <20211116224850.291053858037@sourceware.org> Date: Tue, 16 Nov 2021 22:48:50 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Nov 2021 22:48:50 -0000 https://gcc.gnu.org/g:73e4d9f1751fd6d3c182988b2f9d0199c86053c9 commit r12-5326-g73e4d9f1751fd6d3c182988b2f9d0199c86053c9 Author: Jonathan Wakely Date: Tue Nov 16 21:00:50 2021 +0000 libstdc++: Fix tests for constexpr std::string Some tests fail when run with -D_GLIBCXX_USE_CXX11_ABI or -stdgnu++20. libstdc++-v3/ChangeLog: * include/bits/basic_string.h (operator<=>): Use constexpr unconditionally. * testsuite/21_strings/basic_string/modifiers/constexpr.cc: Require cxx11-abit effective target. * testsuite/21_strings/headers/string/synopsis.cc: Add conditional constexpr to declarations, and adjust relational operators for C++20. Diff: --- libstdc++-v3/include/bits/basic_string.h | 6 ++-- .../21_strings/basic_string/modifiers/constexpr.cc | 1 + .../21_strings/headers/string/synopsis.cc | 33 ++++++++++++++++++++-- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index b6945f1cdfb..0b7d6c0a981 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -3546,8 +3546,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * greater than, or incomparable with `__rhs`. */ template - _GLIBCXX20_CONSTEXPR - inline auto + constexpr auto operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) noexcept -> decltype(__detail::__char_traits_cmp_cat<_Traits>(0)) @@ -3561,8 +3560,7 @@ _GLIBCXX_END_NAMESPACE_CXX11 * greater than, or incomparable with `__rhs`. */ template - _GLIBCXX20_CONSTEXPR - inline auto + constexpr auto operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, const _CharT* __rhs) noexcept -> decltype(__detail::__char_traits_cmp_cat<_Traits>(0)) diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/constexpr.cc b/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/constexpr.cc index c875a3a19ad..a4627714d9a 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/constexpr.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/modifiers/constexpr.cc @@ -1,5 +1,6 @@ // { dg-options "-std=gnu++20" } // { dg-do compile { target c++20 } } +// { dg-require-effective-target cxx11-abi } #include #include diff --git a/libstdc++-v3/testsuite/21_strings/headers/string/synopsis.cc b/libstdc++-v3/testsuite/21_strings/headers/string/synopsis.cc index f14c4ae831c..f12345ed426 100644 --- a/libstdc++-v3/testsuite/21_strings/headers/string/synopsis.cc +++ b/libstdc++-v3/testsuite/21_strings/headers/string/synopsis.cc @@ -26,6 +26,12 @@ # define NOTHROW #endif +#if __cplusplus >= 202002L +# define CONSTEXPR constexpr +#else +# define CONSTEXPR +#endif + namespace std { // lib.char.traits, character traits: template @@ -40,33 +46,52 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 _GLIBCXX_END_NAMESPACE_CXX11 template + CONSTEXPR basic_string operator+(const basic_string& lhs, const basic_string& rhs); template + CONSTEXPR basic_string operator+(const charT* lhs, const basic_string& rhs); template + CONSTEXPR basic_string operator+(charT lhs, const basic_string& rhs); template + CONSTEXPR basic_string operator+(const basic_string& lhs, const charT* rhs); template + CONSTEXPR basic_string operator+(const basic_string& lhs, charT rhs); template + CONSTEXPR bool operator==(const basic_string& lhs, const basic_string& rhs) NOTHROW; template - bool operator==(const charT* lhs, - const basic_string& rhs); - template + CONSTEXPR bool operator==(const basic_string& lhs, const charT* rhs); + +#if __cpp_lib_three_way_comparison + template + constexpr + bool operator<=>(const basic_string& lhs, + const basic_string& rhs) NOTHROW; + template + constexpr + bool operator<=>(const basic_string& lhs, + const charT* rhs); +#else + template + CONSTEXPR + bool operator==(const charT* lhs, + const basic_string& rhs); template bool operator!=(const basic_string& lhs, const basic_string& rhs) NOTHROW; @@ -114,9 +139,11 @@ _GLIBCXX_END_NAMESPACE_CXX11 template bool operator>=(const charT* lhs, const basic_string& rhs); +#endif // lib.string.special: template + CONSTEXPR void swap(basic_string& lhs, basic_string& rhs) #if __cplusplus >= 201103L