summaryrefslogtreecommitdiffstats
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-05-17 14:50:32 +0100
committerJonathan Wakely <jwakely@redhat.com>2022-05-17 20:50:31 +0100
commit5f1ce85135a92481307f2eb4ad805bc53f6137a3 (patch)
treec070bc7f3a74a72ca6f4f423f4e61643bbdd33c0 /libstdc++-v3
parentRevert 'Use more ARRAY_SIZE.' for mkoffload (diff)
downloadgcc-5f1ce85135a92481307f2eb4ad805bc53f6137a3.tar.gz
gcc-5f1ce85135a92481307f2eb4ad805bc53f6137a3.tar.bz2
gcc-5f1ce85135a92481307f2eb4ad805bc53f6137a3.tar.xz
libstdc++: Add attributes to <system_error> 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.
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/include/bits/ios_base.h6
-rw-r--r--libstdc++-v3/include/std/future3
-rw-r--r--libstdc++-v3/include/std/system_error23
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
205 205
206 template <> struct is_error_code_enum<io_errc> : public true_type { }; 206 template <> struct is_error_code_enum<io_errc> : public true_type { };
207 207
208 const error_category& iostream_category() noexcept; 208 [[__nodiscard__, __gnu__::__const__]]
209 const error_category&
210 iostream_category() noexcept;
209 211
212 [[__nodiscard__]]
210 inline error_code 213 inline error_code
211 make_error_code(io_errc __e) noexcept 214 make_error_code(io_errc __e) noexcept
212 { return error_code(static_cast<int>(__e), iostream_category()); } 215 { return error_code(static_cast<int>(__e), iostream_category()); }
213 216
217 [[__nodiscard__]]
214 inline error_condition 218 inline error_condition
215 make_error_condition(io_errc __e) noexcept 219 make_error_condition(io_errc __e) noexcept
216 { return error_condition(static_cast<int>(__e), iostream_category()); } 220 { return error_condition(static_cast<int>(__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
82 struct is_error_code_enum<future_errc> : public true_type { }; 82 struct is_error_code_enum<future_errc> : public true_type { };
83 83
84 /// Points to a statically-allocated object derived from error_category. 84 /// Points to a statically-allocated object derived from error_category.
85 [[__nodiscard__, __gnu__::__const__]]
85 const error_category& 86 const error_category&
86 future_category() noexcept; 87 future_category() noexcept;
87 88
88 /// Overload of make_error_code for `future_errc`. 89 /// Overload of make_error_code for `future_errc`.
90 [[__nodiscard__]]
89 inline error_code 91 inline error_code
90 make_error_code(future_errc __errc) noexcept 92 make_error_code(future_errc __errc) noexcept
91 { return error_code(static_cast<int>(__errc), future_category()); } 93 { return error_code(static_cast<int>(__errc), future_category()); }
92 94
93 /// Overload of make_error_condition for `future_errc`. 95 /// Overload of make_error_condition for `future_errc`.
96 [[__nodiscard__]]
94 inline error_condition 97 inline error_condition
95 make_error_condition(future_errc __errc) noexcept 98 make_error_condition(future_errc __errc) noexcept
96 { return error_condition(static_cast<int>(__errc), future_category()); } 99 { return error_condition(static_cast<int>(__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)
153 equivalent(const error_code& __code, int __i) const noexcept; 153 equivalent(const error_code& __code, int __i) const noexcept;
154 154
155 /// An error_category only compares equal to itself. 155 /// An error_category only compares equal to itself.
156 [[__nodiscard__]]
156 bool 157 bool
157 operator==(const error_category& __other) const noexcept 158 operator==(const error_category& __other) const noexcept
158 { return this == &__other; } 159 { return this == &__other; }
159 160
160 /// Ordered comparison that defines a total order for error categories. 161 /// Ordered comparison that defines a total order for error categories.
161#if __cpp_lib_three_way_comparison 162#if __cpp_lib_three_way_comparison
163 [[nodiscard]]
162 strong_ordering 164 strong_ordering
163 operator<=>(const error_category& __rhs) const noexcept 165 operator<=>(const error_category& __rhs) const noexcept
164 { return std::compare_three_way()(this, &__rhs); } 166 { return std::compare_three_way()(this, &__rhs); }
@@ -176,10 +178,14 @@ _GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
176 // DR 890. 178 // DR 890.
177 179
178 /// Error category for `errno` error codes. 180 /// Error category for `errno` error codes.
179 _GLIBCXX_CONST const error_category& generic_category() noexcept; 181 [[__nodiscard__, __gnu__::__const__]]
182 const error_category&
183 generic_category() noexcept;
180 184
181 /// Error category for other error codes defined by the OS. 185 /// Error category for other error codes defined by the OS.
182 _GLIBCXX_CONST const error_category& system_category() noexcept; 186 [[__nodiscard__, __gnu__::__const__]]
187 const error_category&
188 system_category() noexcept;
183 189
184 /// @} 190 /// @}
185 191
@@ -241,10 +247,12 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
241 { return *this = make_error_code(__e); } 247 { return *this = make_error_code(__e); }
242 248
243 /// The error value. 249 /// The error value.
250 [[__nodiscard__]]
244 int 251 int
245 value() const noexcept { return _M_value; } 252 value() const noexcept { return _M_value; }
246 253
247 /// The error category that this error belongs to. 254 /// The error category that this error belongs to.
255 [[__nodiscard__]]
248 const error_category& 256 const error_category&
249 category() const noexcept { return *_M_cat; } 257 category() const noexcept { return *_M_cat; }
250 258
@@ -259,6 +267,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
259 { return category().message(value()); } 267 { return category().message(value()); }
260 268
261 /// Test whether `value()` is non-zero. 269 /// Test whether `value()` is non-zero.
270 [[__nodiscard__]]
262 explicit operator bool() const noexcept 271 explicit operator bool() const noexcept
263 { return _M_value != 0; } 272 { return _M_value != 0; }
264 273
@@ -278,6 +287,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
278 * @relates error_code 287 * @relates error_code
279 * @since C++11 288 * @since C++11
280 */ 289 */
290 [[__nodiscard__]]
281 inline error_code 291 inline error_code
282 make_error_code(errc __e) noexcept 292 make_error_code(errc __e) noexcept
283 { return error_code(static_cast<int>(__e), generic_category()); } 293 { return error_code(static_cast<int>(__e), generic_category()); }
@@ -291,6 +301,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
291 * @since C++11 301 * @since C++11
292 */ 302 */
293#if __cpp_lib_three_way_comparison 303#if __cpp_lib_three_way_comparison
304 [[nodiscard]]
294 inline strong_ordering 305 inline strong_ordering
295 operator<=>(const error_code& __lhs, const error_code& __rhs) noexcept 306 operator<=>(const error_code& __lhs, const error_code& __rhs) noexcept
296 { 307 {
@@ -371,10 +382,12 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
371 // C++11 19.5.3.4 observers 382 // C++11 19.5.3.4 observers
372 383
373 /// The error value. 384 /// The error value.
385 [[__nodiscard__]]
374 int 386 int
375 value() const noexcept { return _M_value; } 387 value() const noexcept { return _M_value; }
376 388
377 /// The error category that this error belongs to. 389 /// The error category that this error belongs to.
390 [[__nodiscard__]]
378 const error_category& 391 const error_category&
379 category() const noexcept { return *_M_cat; } 392 category() const noexcept { return *_M_cat; }
380 393
@@ -385,6 +398,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
385 { return category().message(value()); } 398 { return category().message(value()); }
386 399
387 /// Test whether `value()` is non-zero. 400 /// Test whether `value()` is non-zero.
401 [[__nodiscard__]]
388 explicit operator bool() const noexcept 402 explicit operator bool() const noexcept
389 { return _M_value != 0; } 403 { return _M_value != 0; }
390 404
@@ -404,6 +418,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
404 * @relates error_condition 418 * @relates error_condition
405 * @since C++11 419 * @since C++11
406 */ 420 */
421 [[__nodiscard__]]
407 inline error_condition 422 inline error_condition
408 make_error_condition(errc __e) noexcept 423 make_error_condition(errc __e) noexcept
409 { return error_condition(static_cast<int>(__e), generic_category()); } 424 { return error_condition(static_cast<int>(__e), generic_category()); }
@@ -417,6 +432,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
417 * @relates error_condition 432 * @relates error_condition
418 * @since C++11 433 * @since C++11
419 */ 434 */
435 [[__nodiscard__]]
420 inline bool 436 inline bool
421 operator==(const error_code& __lhs, const error_code& __rhs) noexcept 437 operator==(const error_code& __lhs, const error_code& __rhs) noexcept
422 { 438 {
@@ -432,6 +448,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
432 * @relates error_condition 448 * @relates error_condition
433 * @since C++11 449 * @since C++11
434 */ 450 */
451 [[__nodiscard__]]
435 inline bool 452 inline bool
436 operator==(const error_code& __lhs, const error_condition& __rhs) noexcept 453 operator==(const error_code& __lhs, const error_condition& __rhs) noexcept
437 { 454 {
@@ -446,6 +463,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
446 * @relates error_condition 463 * @relates error_condition
447 * @since C++11 464 * @since C++11
448 */ 465 */
466 [[__nodiscard__]]
449 inline bool 467 inline bool
450 operator==(const error_condition& __lhs, 468 operator==(const error_condition& __lhs,
451 const error_condition& __rhs) noexcept 469 const error_condition& __rhs) noexcept
@@ -463,6 +481,7 @@ _GLIBCXX_END_INLINE_ABI_NAMESPACE(_V2)
463 * @since C++11 481 * @since C++11
464 */ 482 */
465#if __cpp_lib_three_way_comparison 483#if __cpp_lib_three_way_comparison
484 [[nodiscard]]
466 inline strong_ordering 485 inline strong_ordering
467 operator<=>(const error_condition& __lhs, 486 operator<=>(const error_condition& __lhs,
468 const error_condition& __rhs) noexcept 487 const error_condition& __rhs) noexcept