From patchwork Wed May 22 22:34:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1938081 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Fhsccoct; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vl5jN5cn8z20KL for ; Thu, 23 May 2024 08:35:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E47AB3865C3C for ; Wed, 22 May 2024 22:35:18 +0000 (GMT) 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 75CB33865C29 for ; Wed, 22 May 2024 22:34:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 75CB33865C29 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 75CB33865C29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716417271; cv=none; b=vtBXz9YO7XbporFlYggcptNZOdOk+SpMNYtnf+VVdJ2bkHLUUnne2sjUOFEVLzPvPiym0Jxjfh4rIPtdRKKvWiOmL7ACJu+79xE8+8FGYKmuPOH/HhHFvtS5p9u8QuTlESDp0LU6bqbf8aUupWLHfYRMxrvVMYLbZuV8xt6f88Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716417271; c=relaxed/simple; bh=XFBxqJSRZs0nLAuq/p9AuZfmF8MlMIIdJhALs5ElwOo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Au0RII1LRT9d6z5rDnOjnQhqPjjs958pjQSM2122B/J1w6686PyO2eIB28j10aA6/rxjdSHQr8VetHROe3yrVDxvjvVBhI4Onac6G41oXSAmKEqYY7y0ExkwsG1It61bireAM/kFDSKOTIzZQigqgHvl25Y1ptMqE865bCunLqM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716417268; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vw8xOAvqj+D/uKwuyu+NqSDf6HrJjLdN1wa6gl4dcUc=; b=FhsccocteHu7KdgGSUyfA1UVnU9FYm7wL6Ts/VVLcNU0DJGMdV4yxvT8j9RHtYJj+QG8tW /7dhJZUXX5yW8XKxVqczd4JH87QQZPzCdMS0+052nkqaSSMY+TXZbleP3QklLF9aMW7JDK ELeN/9JgdBGlTAM830fM7Q8T8+6s1BE= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-688-44kTAooZMM2Bb6KNpZqQvQ-1; Wed, 22 May 2024 18:34:25 -0400 X-MC-Unique: 44kTAooZMM2Bb6KNpZqQvQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id C57B6380008B; Wed, 22 May 2024 22:34:24 +0000 (UTC) Received: from localhost (unknown [10.42.28.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95B1EC15BB1; Wed, 22 May 2024 22:34:24 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add [[nodiscard]] to some std::locale functions Date: Wed, 22 May 2024 23:34:15 +0100 Message-ID: <20240522223423.345867-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Pushed to trunk. -- >8 -- libstdc++-v3/ChangeLog: * include/bits/locale_classes.h (locale::combine) (locale::name, locale::operator==, locale::operator!=) (locale::operator(), locale::classic): Add nodiscard attribute. * include/bits/locale_classes.tcc (has_facet, use_facet): Likewise. * testsuite/22_locale/locale/cons/12438.cc: Add dg-warning for nodiscard diagnostic. * testsuite/22_locale/locale/cons/2.cc: Cast use_facet expression to void, to suppress diagnostic. * testsuite/22_locale/locale/cons/unicode.cc: Likewise. * testsuite/22_locale/locale/operations/2.cc: Add dg-warning. --- libstdc++-v3/include/bits/locale_classes.h | 7 ++++++- libstdc++-v3/include/bits/locale_classes.tcc | 2 ++ libstdc++-v3/testsuite/22_locale/locale/cons/12438.cc | 2 +- libstdc++-v3/testsuite/22_locale/locale/cons/2.cc | 2 +- libstdc++-v3/testsuite/22_locale/locale/cons/unicode.cc | 2 +- libstdc++-v3/testsuite/22_locale/locale/operations/2.cc | 2 +- 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/include/bits/locale_classes.h b/libstdc++-v3/include/bits/locale_classes.h index a2e94217006..50a748066f1 100644 --- a/libstdc++-v3/include/bits/locale_classes.h +++ b/libstdc++-v3/include/bits/locale_classes.h @@ -240,6 +240,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @throw std::runtime_error if __other has no facet of type _Facet. */ template + _GLIBCXX_NODISCARD locale combine(const locale& __other) const; @@ -248,7 +249,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @brief Return locale name. * @return Locale name or "*" if unnamed. */ - _GLIBCXX_DEFAULT_ABI_TAG + _GLIBCXX_NODISCARD _GLIBCXX_DEFAULT_ABI_TAG string name() const; @@ -269,6 +270,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @return True if other and this refer to the same locale instance, are * copies, or have the same name. False otherwise. */ + _GLIBCXX_NODISCARD bool operator==(const locale& __other) const throw(); @@ -279,6 +281,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __other The locale to compare against. * @return ! (*this == __other) */ + _GLIBCXX_NODISCARD bool operator!=(const locale& __other) const throw() { return !(this->operator==(__other)); } @@ -300,6 +303,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @return True if collate<_Char> facet compares __s1 < __s2, else false. */ template + _GLIBCXX_NODISCARD bool operator()(const basic_string<_Char, _Traits, _Alloc>& __s1, const basic_string<_Char, _Traits, _Alloc>& __s2) const; @@ -321,6 +325,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /** * @brief Return reference to the C locale. */ + _GLIBCXX_NODISCARD static const locale& classic(); diff --git a/libstdc++-v3/include/bits/locale_classes.tcc b/libstdc++-v3/include/bits/locale_classes.tcc index 00eeb7dd9f8..c79574e58de 100644 --- a/libstdc++-v3/include/bits/locale_classes.tcc +++ b/libstdc++-v3/include/bits/locale_classes.tcc @@ -173,6 +173,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @return true if @p __loc contains a facet of type _Facet, else false. */ template + _GLIBCXX_NODISCARD inline bool has_facet(const locale& __loc) _GLIBCXX_USE_NOEXCEPT { @@ -202,6 +203,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdangling-reference" template + _GLIBCXX_NODISCARD inline const _Facet& use_facet(const locale& __loc) { diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/12438.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/12438.cc index 7ff3a487745..4838e1ba693 100644 --- a/libstdc++-v3/testsuite/22_locale/locale/cons/12438.cc +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/12438.cc @@ -45,7 +45,7 @@ void test01(int iters) locale loc2 = locale(""); VERIFY( !has_facet(loc2) ); - loc1.combine(loc2); + loc1.combine(loc2); // { dg-warning "nodiscard" "" { target c++17 } } VERIFY( false ); } catch (std::runtime_error&) diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/2.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/2.cc index 12478dbfdc2..dce150effea 100644 --- a/libstdc++-v3/testsuite/22_locale/locale/cons/2.cc +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/2.cc @@ -68,7 +68,7 @@ void test01() { VERIFY( false ); } try - { use_facet(loc02); } + { (void) use_facet(loc02); } catch(bad_cast& obj) { VERIFY( true ); } catch(...) diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/unicode.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/unicode.cc index 24af4142cd9..98d744de91e 100644 --- a/libstdc++-v3/testsuite/22_locale/locale/cons/unicode.cc +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/unicode.cc @@ -79,7 +79,7 @@ void test01() { VERIFY( false ); } try - { use_facet(loc13); } + { (void) use_facet(loc13); } catch(bad_cast& obj) { VERIFY( true ); } catch(...) diff --git a/libstdc++-v3/testsuite/22_locale/locale/operations/2.cc b/libstdc++-v3/testsuite/22_locale/locale/operations/2.cc index 899535137ba..917adecac56 100644 --- a/libstdc++-v3/testsuite/22_locale/locale/operations/2.cc +++ b/libstdc++-v3/testsuite/22_locale/locale/operations/2.cc @@ -48,7 +48,7 @@ void test02() // Derivation, MF check. locale loc_gnu(loc_c, new gnu_collate); gnu_count = 0; - loc_gnu(s01, s02); + loc_gnu(s01, s02); // { dg-warning "nodiscard" "" { target c++17 } } VERIFY( gnu_count == 1 ); }