From patchwork Tue May 17 19:56:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 54110 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 E20E13858434 for ; Tue, 17 May 2022 19:58:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E20E13858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652817528; bh=RG6GpKQo6b/mqcKtE6M+FZtrAy8WcODCJlanCQlmBuY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=TrNZ67PAYY3haUEYiF7xhco0aPq5AGGLc1heCMl3zvNhb1nCzIHf7+eWfgDLW80ro m5QskIZzNd2Pdvk4UmWd/05vi9ZVXi6Vo8yhHUwoya859OrXLONmvKJ49QJo6aW0PB FMb194SgcHmQFfJEp4es/ardw9KJXSuD14Jn3cgU= 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 DF81B3857346 for ; Tue, 17 May 2022 19:56:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DF81B3857346 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-626-n8BTWfExNQ23PdzUgfc7ew-1; Tue, 17 May 2022 15:56:18 -0400 X-MC-Unique: n8BTWfExNQ23PdzUgfc7ew-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 292FA1D9F888; Tue, 17 May 2022 19:56:18 +0000 (UTC) Received: from localhost (unknown [10.33.36.185]) by smtp.corp.redhat.com (Postfix) with ESMTP id E22EE492C3B; Tue, 17 May 2022 19:56:17 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add attributes to and related Date: Tue, 17 May 2022 20:56:17 +0100 Message-Id: <20220517195617.164211-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.7 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, SPF_HELO_NONE, SPF_NONE, 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: 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. -- >8 -- Add the const attribute to std::future_category() and std::iostream_category(), to match the existing attributes on std::generic_category() and std::system_category(). Also add [[nodiscard]] to those functions and to the comparison operators for std::error_code and std::error_condition, and to std::make_error_code and std::make_error_condition overloads. libstdc++-v3/ChangeLog: * include/bits/ios_base.h (io_category): Add const and nodiscard attributes. (make_error_code, make_error_condition): Add nodiscard. * include/std/future (future_category): Add const and nodiscard. (make_error_code, make_error_condition): Add nodiscard. * include/std/system_error (generic_category system_category): Add nodiscard. Replace _GLIBCXX_CONST with C++11 attribute. (error_code::value, error_code::category, error_code::operator bool) (error_condition::value, error_condition::category) (error_condition::operator bool, make_error_code) (make_error_condition, operator==, operator!=, operator<=>): Add nodiscard. --- libstdc++-v3/include/bits/ios_base.h | 6 +++++- libstdc++-v3/include/std/future | 3 +++ libstdc++-v3/include/std/system_error | 23 +++++++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/include/bits/ios_base.h b/libstdc++-v3/include/bits/ios_base.h index bdb30140536..e34097171a5 100644 --- a/libstdc++-v3/include/bits/ios_base.h +++ b/libstdc++-v3/include/bits/ios_base.h @@ -205,12 +205,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template <> struct is_error_code_enum : public true_type { }; - const error_category& iostream_category() noexcept; + [[__nodiscard__, __gnu__::__const__]] + const error_category& + iostream_category() noexcept; + [[__nodiscard__]] inline error_code make_error_code(io_errc __e) noexcept { return error_code(static_cast(__e), iostream_category()); } + [[__nodiscard__]] inline error_condition make_error_condition(io_errc __e) noexcept { return error_condition(static_cast(__e), iostream_category()); } diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future index f7de8ddb0bc..a925d03d19c 100644 --- a/libstdc++-v3/include/std/future +++ b/libstdc++-v3/include/std/future @@ -82,15 +82,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_error_code_enum : public true_type { }; /// Points to a statically-allocated object derived from error_category. + [[__nodiscard__, __gnu__::__const__]] const error_category& future_category() noexcept; /// Overload of make_error_code for `future_errc`. + [[__nodiscard__]] inline error_code make_error_code(future_errc __errc) noexcept { return error_code(static_cast(__errc), future_category()); } /// Overload of make_error_condition for `future_errc`. + [[__nodiscard__]] inline error_condition make_error_condition(future_errc __errc) noexcept { return error_condition(static_cast(__errc), future_category()); } diff --git a/libstdc++-v3/include/std/system_error b/libstdc++-v3/include/std/system_error index 95508da73dd..87cf720f6e3 100644 --- a/libstdc++-v3/include/std/system_error +++ b/libstdc++-v3/include/std/system_error @@ -153,12 +153,14 @@ _GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2) equivalent(const error_code& __code, int __i) const noexcept; /// An error_category only compares equal to itself. + [[__nodiscard__]] bool operator==(const error_category& __other) const noexcept { return this == &__other; } /// Ordered comparison that defines a total order for error categories. #if __cpp_lib_three_way_comparison + [[nodiscard]] strong_ordering operator<=>(const error_category& __rhs) const noexcept { return std::compare_three_way()(this, &__rhs); } @@ -176,10 +178,14 @@ _GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2) // DR 890. /// Error category for `errno` error codes. - _GLIBCXX_CONST const error_category& generic_category() noexcept; + [[__nodiscard__, __gnu__::__const__]] + const error_category& + generic_category() noexcept; /// Error category for other error codes defined by the OS. - _GLIBCXX_CONST const error_category& system_category() noexcept; + [[__nodiscard__, __gnu__::__const__]] + const error_category& + system_category() noexcept; /// @} @@ -241,10 +247,12 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) { return *this = make_error_code(__e); } /// The error value. + [[__nodiscard__]] int value() const noexcept { return _M_value; } /// The error category that this error belongs to. + [[__nodiscard__]] const error_category& category() const noexcept { return *_M_cat; } @@ -259,6 +267,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) { return category().message(value()); } /// Test whether `value()` is non-zero. + [[__nodiscard__]] explicit operator bool() const noexcept { return _M_value != 0; } @@ -278,6 +287,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * @relates error_code * @since C++11 */ + [[__nodiscard__]] inline error_code make_error_code(errc __e) noexcept { return error_code(static_cast(__e), generic_category()); } @@ -291,6 +301,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * @since C++11 */ #if __cpp_lib_three_way_comparison + [[nodiscard]] inline strong_ordering operator<=>(const error_code& __lhs, const error_code& __rhs) noexcept { @@ -371,10 +382,12 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) // C++11 19.5.3.4 observers /// The error value. + [[__nodiscard__]] int value() const noexcept { return _M_value; } /// The error category that this error belongs to. + [[__nodiscard__]] const error_category& category() const noexcept { return *_M_cat; } @@ -385,6 +398,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) { return category().message(value()); } /// Test whether `value()` is non-zero. + [[__nodiscard__]] explicit operator bool() const noexcept { return _M_value != 0; } @@ -404,6 +418,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * @relates error_condition * @since C++11 */ + [[__nodiscard__]] inline error_condition make_error_condition(errc __e) noexcept { return error_condition(static_cast(__e), generic_category()); } @@ -417,6 +432,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * @relates error_condition * @since C++11 */ + [[__nodiscard__]] inline bool operator==(const error_code& __lhs, const error_code& __rhs) noexcept { @@ -432,6 +448,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * @relates error_condition * @since C++11 */ + [[__nodiscard__]] inline bool operator==(const error_code& __lhs, const error_condition& __rhs) noexcept { @@ -446,6 +463,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * @relates error_condition * @since C++11 */ + [[__nodiscard__]] inline bool operator==(const error_condition& __lhs, const error_condition& __rhs) noexcept @@ -463,6 +481,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2) * @since C++11 */ #if __cpp_lib_three_way_comparison + [[nodiscard]] inline strong_ordering operator<=>(const error_condition& __lhs, const error_condition& __rhs) noexcept