From patchwork Tue Nov 16 22:49:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 47791 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 981AB385AC36 for ; Tue, 16 Nov 2021 22:49:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 981AB385AC36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637102979; bh=TxM7pHxWrsegtLrIwTwpd6n0KbBfMcsSXbzzOO+CD6c=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=r/E7ZqbxS32z7J0GBiE7TiqHjVt10S2Njn0PKauG9XSZvrmxIUgSdECwFfwO5E89a eMY1t/7SHNo7nyl2sKSi6jx3mspd0Gr5GJ0pc5IX5LYlIKW7jaNjQqTnHde8czgwty FbHe8nLxhKyg3kW/WOnUWDh6ZgNhQs5w1HaUptoQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 0D85D3858037 for ; Tue, 16 Nov 2021 22:49:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0D85D3858037 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-286-Hi_SQPJ-P5Slir6-UCitvQ-1; Tue, 16 Nov 2021 17:49:08 -0500 X-MC-Unique: Hi_SQPJ-P5Slir6-UCitvQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7FA3515720; Tue, 16 Nov 2021 22:49:07 +0000 (UTC) Received: from localhost (unknown [10.33.36.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DF955C1D5; Tue, 16 Nov 2021 22:49:06 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix tests for constexpr std::string Date: Tue, 16 Nov 2021 22:49:05 +0000 Message-Id: <20211116224905.3936029-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Tested powerpc64le-linux, pushed to trunk. 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. --- libstdc++-v3/include/bits/basic_string.h | 6 ++-- .../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