From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id C1212384D1BE; Tue, 28 Mar 2023 23:34:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C1212384D1BE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680046469; bh=epdpcXolQKHlXMoNn7lNHrcE8cpYyVG6IB9LFS0mXs8=; h=From:To:Subject:Date:From; b=PEKKXxlIy5UyBO1oYn92Izjje3DI9wZAjFY+stFu6CdKH3ddaX2j95SbXdj6uIR/M ZHixLmCjr71OPkxY8OifNaEe9jHQTRJcgz6SWnwMIJBcSETVr4Zt99nxlpUFa5yS57 MqiJNdNqJHbZJpdka1bWMH42cFF3DeYtD0JuhE8w= 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-9337] libstdc++: Add attributes to and related X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: dff9e0197eb598f3507020ad0231797e33a18825 X-Git-Newrev: 0f536edda07aee148b06bbe3b26305d6073c35be Message-Id: <20230328233429.C1212384D1BE@sourceware.org> Date: Tue, 28 Mar 2023 23:34:29 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0f536edda07aee148b06bbe3b26305d6073c35be commit r12-9337-g0f536edda07aee148b06bbe3b26305d6073c35be Author: Jonathan Wakely Date: Tue May 17 14:50:32 2022 +0100 libstdc++: Add attributes to and related 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. (cherry picked from commit 5f1ce85135a92481307f2eb4ad805bc53f6137a3) Diff: --- 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 2c33003ed07..5b554548ecd 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 77689b35449..ba1f28c6c75 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 e7415a44ed1..31d2f584251 100644 --- a/libstdc++-v3/include/std/system_error +++ b/libstdc++-v3/include/std/system_error @@ -153,12 +153,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION 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_NAMESPACE_VERSION // 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; /// @} } // end inline namespace @@ -240,10 +246,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { 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; } @@ -258,6 +266,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return category().message(value()); } /// Test whether `value()` is non-zero. + [[__nodiscard__]] explicit operator bool() const noexcept { return _M_value != 0; } @@ -277,6 +286,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @relates error_code * @since C++11 */ + [[__nodiscard__]] inline error_code make_error_code(errc __e) noexcept { return error_code(static_cast(__e), generic_category()); } @@ -290,6 +300,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @since C++11 */ #if __cpp_lib_three_way_comparison + [[nodiscard]] inline strong_ordering operator<=>(const error_code& __lhs, const error_code& __rhs) noexcept { @@ -370,10 +381,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // 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; } @@ -384,6 +397,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return category().message(value()); } /// Test whether `value()` is non-zero. + [[__nodiscard__]] explicit operator bool() const noexcept { return _M_value != 0; } @@ -403,6 +417,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @relates error_condition * @since C++11 */ + [[__nodiscard__]] inline error_condition make_error_condition(errc __e) noexcept { return error_condition(static_cast(__e), generic_category()); } @@ -416,6 +431,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @relates error_condition * @since C++11 */ + [[__nodiscard__]] inline bool operator==(const error_code& __lhs, const error_code& __rhs) noexcept { @@ -431,6 +447,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @relates error_condition * @since C++11 */ + [[__nodiscard__]] inline bool operator==(const error_code& __lhs, const error_condition& __rhs) noexcept { @@ -445,6 +462,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @relates error_condition * @since C++11 */ + [[__nodiscard__]] inline bool operator==(const error_condition& __lhs, const error_condition& __rhs) noexcept @@ -462,6 +480,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @since C++11 */ #if __cpp_lib_three_way_comparison + [[nodiscard]] inline strong_ordering operator<=>(const error_condition& __lhs, const error_condition& __rhs) noexcept