From patchwork Wed Aug 10 18:31:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 1665335 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=a9yhlBV7; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4M2z7g3nymz9sFs for ; Thu, 11 Aug 2022 04:32:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2EA213857359 for ; Wed, 10 Aug 2022 18:32:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2EA213857359 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1660156341; bh=C0gfK96mTBzjDn0uMPEJ4c8VQFZ8AKNJCkn1v67j48M=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=a9yhlBV7vC8fiByXh5rymrmBjSnTl+cbrui6rKbYoRuLbCcODhvFxSyDhTMtaFouI Argj3fkpeGJmk/vLsA1OcNW0D8+WlYdfRJWSYcO+mRnyko7WrbYi9VXDF4s+DBrliG 99QYXs80QBJvdurcLYz9ic7RjptrVItplEGZZABk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 737B03858430; Wed, 10 Aug 2022 18:31:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 737B03858430 Received: by mail-wr1-x42c.google.com with SMTP id bs25so250459wrb.2; Wed, 10 Aug 2022 11:31:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc; bh=C0gfK96mTBzjDn0uMPEJ4c8VQFZ8AKNJCkn1v67j48M=; b=ixDbUYQXlH3xJXtAG/hbsvAMno7nZMRfnRGYmtHfTOKTLmB4f/l3W8OqewngD/4JbY qAmIisyQ65QF1N6JiBOmwdjdcGodLFKAL9fHT7lQfk7DYJNIRmzTaSgE34PvOmVROJyx u5UikgwwMUiYvZi2UHxJdPchXpGPpXiCWSwEP54pnZ2tPdh8lk7uGnOuOsgugkKkh6nB DAUgbMjrefzmc5PaCgFSeJhRp52Cw33ey+iUR0B4dBOgf46HBptjMDIDJhX3SE3bem+2 PBo1Bjg+GW8dTgnQWSF+QjaENmp6Z9ONnCFtw4Lp2YCAVL4jJC3uXTFlDDdJnTqpYp7Z SyvA== X-Gm-Message-State: ACgBeo2NiEpao8F24bfu4h84PLda0NzMei4CdDY0UPSrhvyl5Dv+wllH aj1RW3E11+Ijp6BR9l1/xDfndv4iSRo= X-Google-Smtp-Source: AA6agR7sN6QdicTufZGByDekYwoEPfa26IC5dZWA0WR/cTHVZMLlNYRQ+nsptqYjZqmL6zORrANr0Q== X-Received: by 2002:a5d:59a4:0:b0:222:cf54:70e1 with SMTP id p4-20020a5d59a4000000b00222cf5470e1mr8960075wrr.637.1660156282708; Wed, 10 Aug 2022 11:31:22 -0700 (PDT) Received: from [10.40.1.1] ([109.190.253.15]) by smtp.googlemail.com with ESMTPSA id t11-20020a5d534b000000b00222c96d8656sm9299751wrv.114.2022.08.10.11.31.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Aug 2022 11:31:21 -0700 (PDT) Message-ID: Date: Wed, 10 Aug 2022 20:31:17 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: "libstdc++@gcc.gnu.org" Subject: [PATCH] Complete __gnu_test::basic_string<>::compare support X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: =?utf-8?q?Fran=C3=A7ois_Dumont_via_Gcc-patches?= From: =?utf-8?q?Fran=C3=A7ois_Dumont?= Reply-To: =?utf-8?q?Fran=C3=A7ois_Dumont?= Cc: gcc-patches Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Here is another patch to complete __gnu_debug::basic_string<> Standard conformity. This one is adding the missing compare overloads. I also would like to propose to change how __gnu_debug::basic_string<> is tested. I considered activating checks when _GLIBCXX_ASSERTIONS is defined but it turns out that to do so this light-debug mode should then also consider _GLIBCXX_DEBUG_PEDANTIC. I prefer to avoid this. So I restored previous behavior. I'm now checking for the _GLIBCXX_TEST_DEBUG_STRING macro to force usage of . This way I am testing it using: make check-debug CXXFLAGS=-D_GLIBCXX_TEST_DEBUG_STRING     libstdc++: Add __gnu_debug::basic_string<>::compare overloads     Rather than adding those implementations we are ading a:     using _Base::compare;     so that any compare method not implemented at __gnu_debug::basic_string     level are injected from the base class.     Also review how __gnu_debug::basic_string is tested. Now require to define     _GLIBCXX_TEST_DEBUG_STRING when running 'make check-debug'.     libstdc++-v3/ChangeLog             * include/debug/string: Add using _Base::compare.             (__gnu_debug::basic_string<>::compare(const basic_string<>&)): Remove.             (__gnu_debug::basic_string<>::compare(size_type, size_type, const basic_string<>&)):             Remove.             (__gnu_debug::basic_string<>::compare(size_type, size_type, const basic_string<>&,             size_type, size_type)): Remove.             * testsuite/util/testsuite_string.h [_GLIBCXX_TEST_DEBUG_STRING]: Include .             * testsuite/21_strings/basic_string/operations/compare/char/1.cc: Include testsuite_string.h             and use __gnu_test::string.             * testsuite/21_strings/basic_string/operations/compare/char/13650.cc: Likewise.             * testsuite/21_strings/basic_string/operations/compare/char/2.cc: Likewise.             * testsuite/21_strings/basic_string/operations/rfind/char/1.cc: Likewise.             * testsuite/21_strings/basic_string/operations/rfind/char/2.cc: Likewise.             * testsuite/21_strings/basic_string/operations/rfind/char/3.cc: Likewise.             * testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc: Include testsuite_string.h             and use __gnu_test::wstring.             * testsuite/21_strings/basic_string/operations/compare/wchar_t/13650.cc: Likewise.             * testsuite/21_strings/basic_string/operations/compare/wchar_t/2.cc: Likewise. Tested under Linux x86_64. Ok to commit ? François diff --git a/libstdc++-v3/include/debug/string b/libstdc++-v3/include/debug/string index a4482db4af5..c32eb41eacd 100644 --- a/libstdc++-v3/include/debug/string +++ b/libstdc++-v3/include/debug/string @@ -1002,22 +1002,11 @@ namespace __gnu_debug substr(size_type __pos = 0, size_type __n = _Base::npos) const { return basic_string(_Base::substr(__pos, __n)); } - int - compare(const basic_string& __str) const - { return _Base::compare(__str); } - - int - compare(size_type __pos1, size_type __n1, - const basic_string& __str) const - { return _Base::compare(__pos1, __n1, __str); } - - int - compare(size_type __pos1, size_type __n1, const basic_string& __str, - size_type __pos2, size_type __n2) const - { return _Base::compare(__pos1, __n1, __str, __pos2, __n2); } + using _Base::compare; + _GLIBCXX20_CONSTEXPR int - compare(const _CharT* __s) const + compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT { __glibcxx_check_string(__s); return _Base::compare(__s); @@ -1025,6 +1014,7 @@ namespace __gnu_debug // _GLIBCXX_RESOLVE_LIB_DEFECTS // 5. string::compare specification questionable + _GLIBCXX20_CONSTEXPR int compare(size_type __pos1, size_type __n1, const _CharT* __s) const { @@ -1034,6 +1024,7 @@ namespace __gnu_debug // _GLIBCXX_RESOLVE_LIB_DEFECTS // 5. string::compare specification questionable + _GLIBCXX20_CONSTEXPR int compare(size_type __pos1, size_type __n1,const _CharT* __s, size_type __n2) const diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/char/1.cc index 0bef0d2dd3d..c04b83c4896 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/char/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/char/1.cc @@ -29,7 +29,7 @@ // NB compare should be thought of as a lexographical compare, ie how // things would be sorted in a dictionary. -#include +#include #include #include @@ -67,7 +67,7 @@ test_value(int result, want_value expected) int test01() { - using namespace std; + using namespace __gnu_test; string str_0("costa rica"); string str_1("costa marbella"); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/char/13650.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/char/13650.cc index 96fd2f14b33..ce956235f83 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/char/13650.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/char/13650.cc @@ -19,13 +19,13 @@ // 21.3.6.8 basic_string::compare [lib.string::compare] -#include +#include #include // libstdc++/13650 void test01() { - using namespace std; + using namespace __gnu_test; const char lit_01[] = { 'w', 'e', '\0', 'r', 'd' }; const char lit_02[] = { 'w', 'e', 'i', '\0', 'd' }; diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/char/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/char/2.cc index 17e87526c26..fca154355ff 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/char/2.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/char/2.cc @@ -19,14 +19,14 @@ // [string::compare] -#include +#include #include void test03() { std::string_view str1("foobar"); - std::string str2("foobar"); + __gnu_test::string str2("foobar"); auto x = str2.compare(str1); VERIFY (x == 0); @@ -52,7 +52,7 @@ test03() void test04() { - const std::string str("a"); + const __gnu_test::string str("a"); char c = 'a'; int res = str.compare(0, 1, &c, 1); VERIFY ( !res ); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc index 97a873a55cf..aa5c1680045 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/1.cc @@ -29,7 +29,7 @@ // NB compare should be thought of as a lexographical compare, ie how // things would be sorted in a dictionary. -#include +#include #include enum want_value {lt=0, z=1, gt=2}; @@ -67,7 +67,7 @@ test_value(int result, want_value expected) int test01() { - using namespace std; + using namespace __gnu_test; wstring str_0(L"costa rica"); wstring str_1(L"costa marbella"); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/13650.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/13650.cc index 1825c6b3b30..f3dd4ebaf43 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/13650.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/13650.cc @@ -19,13 +19,13 @@ // 21.3.6.8 basic_string::compare [lib.string::compare] -#include +#include #include // libstdc++/13650 void test01() { - using namespace std; + using namespace __gnu_test; const wchar_t lit_01[] = { L'w', L'e', L'\0', L'r', L'd' }; const wchar_t lit_02[] = { L'w', L'e', L'i', L'\0', L'd' }; diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/2.cc index dd703c19868..c6d219a42ec 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/2.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/compare/wchar_t/2.cc @@ -19,14 +19,14 @@ // [string::compare] -#include +#include #include void test03() { std::wstring_view str1(L"foobar"); - std::wstring str2(L"foobar"); + __gnu_test::wstring str2(L"foobar"); auto x = str2.compare(str1); VERIFY (x == 0); @@ -52,7 +52,7 @@ test03() void test04() { - const std::wstring str(L"a"); + const __gnu_test::wstring str(L"a"); wchar_t c = L'a'; int res = str.compare(0, 1, &c, 1); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/rfind/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/rfind/char/1.cc index 73843b03a9a..76fcb079117 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/rfind/char/1.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/rfind/char/1.cc @@ -17,23 +17,23 @@ // with this library; see the file COPYING3. If not see // . -#include +#include #include // 21.3.6.2 basic_string rfind void test01(void) { - typedef std::string::size_type csize_type; - typedef std::string::const_reference cref; - typedef std::string::reference ref; - csize_type npos = std::string::npos; + typedef __gnu_test::string::size_type csize_type; + typedef __gnu_test::string::const_reference cref; + typedef __gnu_test::string::reference ref; + csize_type npos = __gnu_test::string::npos; csize_type csz01, csz02; const char str_lit01[] = "mave"; - const std::string str01("mavericks, santa cruz"); - std::string str02(str_lit01); - std::string str03("s, s"); - std::string str04; + const __gnu_test::string str01("mavericks, santa cruz"); + __gnu_test::string str02(str_lit01); + __gnu_test::string str03("s, s"); + __gnu_test::string str04; // size_type rfind(const string&, size_type pos = 0) const; csz01 = str01.rfind(str01); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/rfind/char/2.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/rfind/char/2.cc index 587965505d5..9fecfcf80f1 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/rfind/char/2.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/rfind/char/2.cc @@ -17,14 +17,14 @@ // with this library; see the file COPYING3. If not see // . -#include +#include #include // 21.3.6.4 basic_string::find_last_of void test02() { - std::string z("ab"); - std::string::size_type pos; + __gnu_test::string z("ab"); + __gnu_test::string::size_type pos; pos = z.find_last_of("ab"); VERIFY( pos == 1 ); pos = z.find_last_of("Xa"); @@ -32,13 +32,13 @@ void test02() pos = z.find_last_of("Xb"); VERIFY( pos == 1 ); pos = z.find_last_of("XYZ"); - VERIFY( pos == std::string::npos ); + VERIFY( pos == __gnu_test::string::npos ); pos = z.find_last_of('a'); VERIFY( pos == 0 ); pos = z.find_last_of('b'); VERIFY( pos == 1 ); pos = z.find_last_of('X'); - VERIFY( pos == std::string::npos ); + VERIFY( pos == __gnu_test::string::npos ); } int main() diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/rfind/char/3.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/rfind/char/3.cc index 1ff9c94ba5b..69471e67bf1 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/rfind/char/3.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/rfind/char/3.cc @@ -17,23 +17,23 @@ // with this library; see the file COPYING3. If not see // . -#include +#include #include // 21.3.6.6 basic_string::find_last_not_of void test03() { - typedef std::string::size_type csize_type; - std::string::size_type pos; - csize_type npos = std::string::npos; + typedef __gnu_test::string::size_type csize_type; + __gnu_test::string::size_type pos; + csize_type npos = __gnu_test::string::npos; - std::string x; + __gnu_test::string x; pos = x.find_last_not_of('X'); VERIFY( pos == npos ); pos = x.find_last_not_of("XYZ"); VERIFY( pos == npos ); - std::string y("a"); + __gnu_test::string y("a"); pos = y.find_last_not_of('X'); VERIFY( pos == 0 ); pos = y.find_last_not_of('a'); @@ -43,7 +43,7 @@ void test03() pos = y.find_last_not_of("a"); VERIFY( pos == npos ); - std::string z("ab"); + __gnu_test::string z("ab"); pos = z.find_last_not_of('X'); VERIFY( pos == 1 ); pos = z.find_last_not_of("XYZ"); diff --git a/libstdc++-v3/testsuite/util/testsuite_string.h b/libstdc++-v3/testsuite/util/testsuite_string.h index 7121ff8ec6d..7e61d984bdb 100644 --- a/libstdc++-v3/testsuite/util/testsuite_string.h +++ b/libstdc++-v3/testsuite/util/testsuite_string.h @@ -1,7 +1,7 @@ #ifndef _GLIBCXX_TESTSUITE_STRING_H #define _GLIBCXX_TESTSUITE_STRING_H -#ifdef _GLIBCXX_DEBUG +#if defined(_GLIBCXX_DEBUG) && defined(_GLIBCXX_TEST_DEBUG_STRING) # include namespace __gnu_test {