]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add attributes to <system_error> and related
authorJonathan Wakely <jwakely@redhat.com>
Tue, 17 May 2022 13:50:32 +0000 (14:50 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 17 May 2022 19:50:31 +0000 (20:50 +0100)
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
libstdc++-v3/include/std/future
libstdc++-v3/include/std/system_error

index bdb30140536cbd3de18e344613e70ae93b1da8b9..e34097171a5d61d8d2b39edd830ffa4bfe311826 100644 (file)
@@ -205,12 +205,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template <> struct is_error_code_enum<io_errc> : 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<int>(__e), iostream_category()); }
 
+  [[__nodiscard__]]
   inline error_condition
   make_error_condition(io_errc __e) noexcept
   { return error_condition(static_cast<int>(__e), iostream_category()); }
index f7de8ddb0bc60dfbba64362d06b1a78a160fe7c7..a925d03d19ccf65bcdc8a33db7fecd3f52c8e68b 100644 (file)
@@ -82,15 +82,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct is_error_code_enum<future_errc> : 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<int>(__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<int>(__errc), future_category()); }
index 95508da73dd819e4773a4b12c474dd8e5f76c302..87cf720f6e396b1ced58021da4532ec75090eae1 100644 (file)
@@ -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<int>(__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<int>(__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