]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Consistently use noexcept, constexpr, nodiscard on bitmask ops
authorJonathan Wakely <jwakely@redhat.com>
Mon, 26 Feb 2024 11:47:27 +0000 (11:47 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 28 Feb 2024 11:27:46 +0000 (11:27 +0000)
The bitwise operators for combining bitmask types such as std::launch
are not consistently annotated with noexcept, constexpr, and nodiscard.

This is the subject of LWG 3977, although the proposed resolution
doesn't work. We can make the changes in libstdc++ anyway though.

libstdc++-v3/ChangeLog:

* include/bits/atomic_base.h (operator|, operator&): Add
noexcept.
* include/bits/fs_fwd.h (operator&, operator|, operator^)
(operator~): Add nodiscard to overloads for copy_options, perms,
perm_options, and directory_options.
* include/bits/ios_base.h (operator&, operator|, operator^)
(operator~): Add nodiscard and noexcept to overloads for
_Ios_Fmtflags, _Ios_Openmode, and _Ios_Iostate.
(operator|=, operator&=, operator^=): Add constexpr for C++14.
* include/bits/regex_constants.h (operator&, operator|, operator^)
(operator~): Add nodiscard and noexcept to overloads for
syntax_option_type and match_flag_type.
(operator|=, operator&=, operator^=): Add noexcept.
* include/std/charconv (operator&, operator|, operator^)
(operator~): Add nodiscard to overloads for chars_format.
* include/std/future (operator&, operator|, operator^)
(operator~): Add nodiscard for overloads for launch.
(operator&=, operator|=, operator^=): Add constexpr for C++14.
* include/experimental/bits/fs_fwd.h  (operator&, operator|)
(operator^, operator~): Add nodiscard to overloads for
copy_options, perms, and directory_options.
* testsuite/27_io/ios_base/types/fmtflags/bitmask_operators.cc:
Add dg-warning for nodiscard warnings.
* testsuite/27_io/ios_base/types/iostate/bitmask_operators.cc:
Likewise.
* testsuite/27_io/ios_base/types/openmode/bitmask_operators.cc:
Likewise.
* testsuite/27_io/filesystem/operations/bitmask_types.cc:
New test.

libstdc++-v3/include/bits/atomic_base.h
libstdc++-v3/include/bits/fs_fwd.h
libstdc++-v3/include/bits/ios_base.h
libstdc++-v3/include/bits/regex_constants.h
libstdc++-v3/include/experimental/bits/fs_fwd.h
libstdc++-v3/include/std/charconv
libstdc++-v3/include/std/future
libstdc++-v3/testsuite/27_io/filesystem/operations/bitmask_types.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/ios_base/types/fmtflags/bitmask_operators.cc
libstdc++-v3/testsuite/27_io/ios_base/types/iostate/bitmask_operators.cc
libstdc++-v3/testsuite/27_io/ios_base/types/openmode/bitmask_operators.cc

index d3a2c4f38056bfba2e181374e3e80dc382115c29..b857b441169e7ddd2efddb32c43ac4cd2206254e 100644 (file)
@@ -100,13 +100,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   /// @endcond
 
   constexpr memory_order
-  operator|(memory_order __m, __memory_order_modifier __mod)
+  operator|(memory_order __m, __memory_order_modifier __mod) noexcept
   {
     return memory_order(int(__m) | int(__mod));
   }
 
   constexpr memory_order
-  operator&(memory_order __m, __memory_order_modifier __mod)
+  operator&(memory_order __m, __memory_order_modifier __mod) noexcept
   {
     return memory_order(int(__m) & int(__mod));
   }
index 6208e799b843ece19685cc6f942201f224540bcb..7e2bc30df30e318012d4f72772327ca4b67c20f5 100644 (file)
@@ -91,6 +91,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
 
   /// @{
   /// @relates copy_options
+  [[nodiscard]]
   constexpr copy_options
   operator&(copy_options __x, copy_options __y) noexcept
   {
@@ -99,6 +100,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) & static_cast<__utype>(__y));
   }
 
+  [[nodiscard]]
   constexpr copy_options
   operator|(copy_options __x, copy_options __y) noexcept
   {
@@ -107,6 +109,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) | static_cast<__utype>(__y));
   }
 
+  [[nodiscard]]
   constexpr copy_options
   operator^(copy_options __x, copy_options __y) noexcept
   {
@@ -115,6 +118,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
   }
 
+  [[nodiscard]]
   constexpr copy_options
   operator~(copy_options __x) noexcept
   {
@@ -161,6 +165,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
 
   /// @{
   /// @relates perms
+  [[nodiscard]]
   constexpr perms
   operator&(perms __x, perms __y) noexcept
   {
@@ -169,6 +174,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) & static_cast<__utype>(__y));
   }
 
+  [[nodiscard]]
   constexpr perms
   operator|(perms __x, perms __y) noexcept
   {
@@ -177,6 +183,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) | static_cast<__utype>(__y));
   }
 
+  [[nodiscard]]
   constexpr perms
   operator^(perms __x, perms __y) noexcept
   {
@@ -185,6 +192,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
   }
 
+  [[nodiscard]]
   constexpr perms
   operator~(perms __x) noexcept
   {
@@ -215,6 +223,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
 
   /// @{
   /// @relates perm_options
+  [[nodiscard]]
   constexpr perm_options
   operator&(perm_options __x, perm_options __y) noexcept
   {
@@ -223,6 +232,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) & static_cast<__utype>(__y));
   }
 
+  [[nodiscard]]
   constexpr perm_options
   operator|(perm_options __x, perm_options __y) noexcept
   {
@@ -231,6 +241,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) | static_cast<__utype>(__y));
   }
 
+  [[nodiscard]]
   constexpr perm_options
   operator^(perm_options __x, perm_options __y) noexcept
   {
@@ -239,6 +250,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
   }
 
+  [[nodiscard]]
   constexpr perm_options
   operator~(perm_options __x) noexcept
   {
@@ -266,6 +278,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
 
   /// @{
   /// @relates directory_options
+  [[nodiscard]]
   constexpr directory_options
   operator&(directory_options __x, directory_options __y) noexcept
   {
@@ -274,6 +287,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) & static_cast<__utype>(__y));
   }
 
+  [[nodiscard]]
   constexpr directory_options
   operator|(directory_options __x, directory_options __y) noexcept
   {
@@ -282,6 +296,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) | static_cast<__utype>(__y));
   }
 
+  [[nodiscard]]
   constexpr directory_options
   operator^(directory_options __x, directory_options __y) noexcept
   {
@@ -290,6 +305,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
   }
 
+  [[nodiscard]]
   constexpr directory_options
   operator~(directory_options __x) noexcept
   {
index f0019649c3dac9c3f45b6850443b2903b937bbc5..b69151c49adf08ee4dca057baf4fdb9345c96158 100644 (file)
@@ -79,32 +79,39 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _S_ios_fmtflags_min = ~__INT_MAX__
     };
 
-  inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags
-  operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
+  _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR
+  inline _Ios_Fmtflags
+  operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW
   { return _Ios_Fmtflags(static_cast<int>(__a) & static_cast<int>(__b)); }
 
-  inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags
-  operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
+  _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR
+  inline _Ios_Fmtflags
+  operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW
   { return _Ios_Fmtflags(static_cast<int>(__a) | static_cast<int>(__b)); }
 
-  inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags
-  operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
+  _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR
+  inline _Ios_Fmtflags
+  operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW
   { return _Ios_Fmtflags(static_cast<int>(__a) ^ static_cast<int>(__b)); }
 
-  inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags
-  operator~(_Ios_Fmtflags __a)
+  _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR
+  inline _Ios_Fmtflags
+  operator~(_Ios_Fmtflags __a) _GLIBCXX_NOTHROW
   { return _Ios_Fmtflags(~static_cast<int>(__a)); }
 
+  _GLIBCXX14_CONSTEXPR
   inline const _Ios_Fmtflags&
-  operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
+  operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW
   { return __a = __a | __b; }
 
+  _GLIBCXX14_CONSTEXPR
   inline const _Ios_Fmtflags&
-  operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
+  operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW
   { return __a = __a & __b; }
 
+  _GLIBCXX14_CONSTEXPR
   inline const _Ios_Fmtflags&
-  operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
+  operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW
   { return __a = __a ^ __b; }
 
 
@@ -122,32 +129,39 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _S_ios_openmode_min = ~__INT_MAX__
     };
 
-  inline _GLIBCXX_CONSTEXPR _Ios_Openmode
-  operator&(_Ios_Openmode __a, _Ios_Openmode __b)
+  _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR
+  inline _Ios_Openmode
+  operator&(_Ios_Openmode __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW
   { return _Ios_Openmode(static_cast<int>(__a) & static_cast<int>(__b)); }
 
-  inline _GLIBCXX_CONSTEXPR _Ios_Openmode
-  operator|(_Ios_Openmode __a, _Ios_Openmode __b)
+  _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR
+  inline _Ios_Openmode
+  operator|(_Ios_Openmode __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW
   { return _Ios_Openmode(static_cast<int>(__a) | static_cast<int>(__b)); }
 
-  inline _GLIBCXX_CONSTEXPR _Ios_Openmode
-  operator^(_Ios_Openmode __a, _Ios_Openmode __b)
+  _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR
+  inline _Ios_Openmode
+  operator^(_Ios_Openmode __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW
   { return _Ios_Openmode(static_cast<int>(__a) ^ static_cast<int>(__b)); }
 
-  inline _GLIBCXX_CONSTEXPR _Ios_Openmode
-  operator~(_Ios_Openmode __a)
+  _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR
+  inline _Ios_Openmode
+  operator~(_Ios_Openmode __a) _GLIBCXX_NOTHROW
   { return _Ios_Openmode(~static_cast<int>(__a)); }
 
+  _GLIBCXX14_CONSTEXPR
   inline const _Ios_Openmode&
-  operator|=(_Ios_Openmode& __a, _Ios_Openmode __b)
+  operator|=(_Ios_Openmode& __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW
   { return __a = __a | __b; }
 
+  _GLIBCXX14_CONSTEXPR
   inline const _Ios_Openmode&
-  operator&=(_Ios_Openmode& __a, _Ios_Openmode __b)
+  operator&=(_Ios_Openmode& __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW
   { return __a = __a & __b; }
 
+  _GLIBCXX14_CONSTEXPR
   inline const _Ios_Openmode&
-  operator^=(_Ios_Openmode& __a, _Ios_Openmode __b)
+  operator^=(_Ios_Openmode& __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW
   { return __a = __a ^ __b; }
 
 
@@ -162,32 +176,39 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _S_ios_iostate_min = ~__INT_MAX__
     };
 
-  inline _GLIBCXX_CONSTEXPR _Ios_Iostate
-  operator&(_Ios_Iostate __a, _Ios_Iostate __b)
+  _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR
+  inline _Ios_Iostate
+  operator&(_Ios_Iostate __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW
   { return _Ios_Iostate(static_cast<int>(__a) & static_cast<int>(__b)); }
 
-  inline _GLIBCXX_CONSTEXPR _Ios_Iostate
-  operator|(_Ios_Iostate __a, _Ios_Iostate __b)
+  _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR
+  inline _Ios_Iostate
+  operator|(_Ios_Iostate __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW
   { return _Ios_Iostate(static_cast<int>(__a) | static_cast<int>(__b)); }
 
-  inline _GLIBCXX_CONSTEXPR _Ios_Iostate
-  operator^(_Ios_Iostate __a, _Ios_Iostate __b)
+  _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR
+  inline _Ios_Iostate
+  operator^(_Ios_Iostate __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW
   { return _Ios_Iostate(static_cast<int>(__a) ^ static_cast<int>(__b)); }
 
-  inline _GLIBCXX_CONSTEXPR _Ios_Iostate
-  operator~(_Ios_Iostate __a)
+  _GLIBCXX_NODISCARD _GLIBCXX_CONSTEXPR
+  inline _Ios_Iostate
+  operator~(_Ios_Iostate __a) _GLIBCXX_NOTHROW
   { return _Ios_Iostate(~static_cast<int>(__a)); }
 
+  _GLIBCXX14_CONSTEXPR
   inline const _Ios_Iostate&
-  operator|=(_Ios_Iostate& __a, _Ios_Iostate __b)
+  operator|=(_Ios_Iostate& __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW
   { return __a = __a | __b; }
 
+  _GLIBCXX14_CONSTEXPR
   inline const _Ios_Iostate&
-  operator&=(_Ios_Iostate& __a, _Ios_Iostate __b)
+  operator&=(_Ios_Iostate& __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW
   { return __a = __a & __b; }
 
-  inline const  _Ios_Iostate&
-  operator^=(_Ios_Iostate& __a, _Ios_Iostate __b)
+  _GLIBCXX14_CONSTEXPR
+  inline const _Ios_Iostate&
+  operator^=(_Ios_Iostate& __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW
   { return __a = __a ^ __b; }
 
 
index 5e567ec2027832cc872f1967252cd1622d95a41b..437895f1dc399f494a91b442b370ffd88b2f581e 100644 (file)
@@ -186,44 +186,48 @@ namespace regex_constants
    */
   _GLIBCXX17_INLINE constexpr syntax_option_type __polynomial = _S_polynomial;
 
-  constexpr inline syntax_option_type
-  operator&(syntax_option_type __a, syntax_option_type __b)
+  [[__nodiscard__]]
+  constexpr syntax_option_type
+  operator&(syntax_option_type __a, syntax_option_type __b) noexcept
   {
     return (syntax_option_type)(static_cast<unsigned int>(__a)
                                & static_cast<unsigned int>(__b));
   }
 
-  constexpr inline syntax_option_type
-  operator|(syntax_option_type __a, syntax_option_type __b)
+  [[__nodiscard__]]
+  constexpr syntax_option_type
+  operator|(syntax_option_type __a, syntax_option_type __b) noexcept
   {
     return (syntax_option_type)(static_cast<unsigned int>(__a)
                                | static_cast<unsigned int>(__b));
   }
 
-  constexpr inline syntax_option_type
-  operator^(syntax_option_type __a, syntax_option_type __b)
+  [[__nodiscard__]]
+  constexpr syntax_option_type
+  operator^(syntax_option_type __a, syntax_option_type __b) noexcept
   {
     return (syntax_option_type)(static_cast<unsigned int>(__a)
                                ^ static_cast<unsigned int>(__b));
   }
 
-  constexpr inline syntax_option_type
-  operator~(syntax_option_type __a)
+  [[__nodiscard__]]
+  constexpr syntax_option_type
+  operator~(syntax_option_type __a) noexcept
   { return (syntax_option_type)(~static_cast<unsigned int>(__a)); }
 
   _GLIBCXX14_CONSTEXPR
   inline syntax_option_type&
-  operator&=(syntax_option_type& __a, syntax_option_type __b)
+  operator&=(syntax_option_type& __a, syntax_option_type __b) noexcept
   { return __a = __a & __b; }
 
   _GLIBCXX14_CONSTEXPR
   inline syntax_option_type&
-  operator|=(syntax_option_type& __a, syntax_option_type __b)
+  operator|=(syntax_option_type& __a, syntax_option_type __b) noexcept
   { return __a = __a | __b; }
 
   _GLIBCXX14_CONSTEXPR
   inline syntax_option_type&
-  operator^=(syntax_option_type& __a, syntax_option_type __b)
+  operator^=(syntax_option_type& __a, syntax_option_type __b) noexcept
   { return __a = __a ^ __b; }
 
   ///@}
@@ -367,44 +371,48 @@ namespace regex_constants
    */
   _GLIBCXX17_INLINE constexpr match_flag_type format_first_only = _S_first_only;
 
-  constexpr inline match_flag_type
-  operator&(match_flag_type __a, match_flag_type __b)
+  [[__nodiscard__]]
+  constexpr match_flag_type
+  operator&(match_flag_type __a, match_flag_type __b) noexcept
   {
     return (match_flag_type)(static_cast<unsigned int>(__a)
                                & static_cast<unsigned int>(__b));
   }
 
-  constexpr inline match_flag_type
-  operator|(match_flag_type __a, match_flag_type __b)
+  [[__nodiscard__]]
+  constexpr match_flag_type
+  operator|(match_flag_type __a, match_flag_type __b) noexcept
   {
     return (match_flag_type)(static_cast<unsigned int>(__a)
                                | static_cast<unsigned int>(__b));
   }
 
-  constexpr inline match_flag_type
-  operator^(match_flag_type __a, match_flag_type __b)
+  [[__nodiscard__]]
+  constexpr match_flag_type
+  operator^(match_flag_type __a, match_flag_type __b) noexcept
   {
     return (match_flag_type)(static_cast<unsigned int>(__a)
                                ^ static_cast<unsigned int>(__b));
   }
 
-  constexpr inline match_flag_type
-  operator~(match_flag_type __a)
+  [[__nodiscard__]]
+  constexpr match_flag_type
+  operator~(match_flag_type __a) noexcept
   { return (match_flag_type)(~static_cast<unsigned int>(__a)); }
 
   _GLIBCXX14_CONSTEXPR
   inline match_flag_type&
-  operator&=(match_flag_type& __a, match_flag_type __b)
+  operator&=(match_flag_type& __a, match_flag_type __b) noexcept
   { return __a = __a & __b; }
 
   _GLIBCXX14_CONSTEXPR
   inline match_flag_type&
-  operator|=(match_flag_type& __a, match_flag_type __b)
+  operator|=(match_flag_type& __a, match_flag_type __b) noexcept
   { return __a = __a | __b; }
 
   _GLIBCXX14_CONSTEXPR
   inline match_flag_type&
-  operator^=(match_flag_type& __a, match_flag_type __b)
+  operator^=(match_flag_type& __a, match_flag_type __b) noexcept
   { return __a = __a ^ __b; }
 
   ///@}
index a5b8feaaa4a2ced8ce8fea55db5cb9de7db358d8..565f2e436926f8d22cebe3a9f54fa284d783b8fe 100644 (file)
@@ -102,6 +102,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
 
   /// @{
   /// @relates copy_options
+  [[__nodiscard__]]
   constexpr copy_options
   operator&(copy_options __x, copy_options __y) noexcept
   {
@@ -110,6 +111,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) & static_cast<__utype>(__y));
   }
 
+  [[__nodiscard__]]
   constexpr copy_options
   operator|(copy_options __x, copy_options __y) noexcept
   {
@@ -118,6 +120,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) | static_cast<__utype>(__y));
   }
 
+  [[__nodiscard__]]
   constexpr copy_options
   operator^(copy_options __x, copy_options __y) noexcept
   {
@@ -126,6 +129,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
   }
 
+  [[__nodiscard__]]
   constexpr copy_options
   operator~(copy_options __x) noexcept
   {
@@ -174,6 +178,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
 
   /// @{
   /// @relates std::experimental::filesystem::perms
+  [[__nodiscard__]]
   constexpr perms
   operator&(perms __x, perms __y) noexcept
   {
@@ -182,6 +187,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) & static_cast<__utype>(__y));
   }
 
+  [[__nodiscard__]]
   constexpr perms
   operator|(perms __x, perms __y) noexcept
   {
@@ -190,6 +196,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) | static_cast<__utype>(__y));
   }
 
+  [[__nodiscard__]]
   constexpr perms
   operator^(perms __x, perms __y) noexcept
   {
@@ -198,6 +205,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
   }
 
+  [[__nodiscard__]]
   constexpr perms
   operator~(perms __x) noexcept
   {
@@ -225,6 +233,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
 
   /// @{
   /// @relates directory_options
+  [[__nodiscard__]]
   constexpr directory_options
   operator&(directory_options __x, directory_options __y) noexcept
   {
@@ -233,6 +242,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) & static_cast<__utype>(__y));
   }
 
+  [[__nodiscard__]]
   constexpr directory_options
   operator|(directory_options __x, directory_options __y) noexcept
   {
@@ -241,6 +251,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) | static_cast<__utype>(__y));
   }
 
+  [[__nodiscard__]]
   constexpr directory_options
   operator^(directory_options __x, directory_options __y) noexcept
   {
@@ -249,6 +260,7 @@ _GLIBCXX_END_NAMESPACE_CXX11
        static_cast<__utype>(__x) ^ static_cast<__utype>(__y));
   }
 
+  [[__nodiscard__]]
   constexpr directory_options
   operator~(directory_options __x) noexcept
   {
index 21c387973f152801ece0369656346b688ba086f7..e516e3b2da86618552182dbbdcb50de42b425719 100644 (file)
@@ -622,18 +622,22 @@ namespace __detail
     scientific = 1, fixed = 2, hex = 4, general = fixed | scientific
   };
 
+  [[nodiscard]]
   constexpr chars_format
   operator|(chars_format __lhs, chars_format __rhs) noexcept
   { return (chars_format)((unsigned)__lhs | (unsigned)__rhs); }
 
+  [[nodiscard]]
   constexpr chars_format
   operator&(chars_format __lhs, chars_format __rhs) noexcept
   { return (chars_format)((unsigned)__lhs & (unsigned)__rhs); }
 
+  [[nodiscard]]
   constexpr chars_format
   operator^(chars_format __lhs, chars_format __rhs) noexcept
   { return (chars_format)((unsigned)__lhs ^ (unsigned)__rhs); }
 
+  [[nodiscard]]
   constexpr chars_format
   operator~(chars_format __fmt) noexcept
   { return (chars_format)~(unsigned)__fmt; }
index 1cba04a0e5a379917021adc1162ee9801c70d48b..9e75ae98b13d2b0cc10f48f2531b3beae6958c76 100644 (file)
@@ -152,33 +152,40 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     deferred = 2
   };
 
+  [[__nodiscard__]]
   constexpr launch operator&(launch __x, launch __y) noexcept
   {
     return static_cast<launch>(
        static_cast<int>(__x) & static_cast<int>(__y));
   }
 
+  [[__nodiscard__]]
   constexpr launch operator|(launch __x, launch __y) noexcept
   {
     return static_cast<launch>(
        static_cast<int>(__x) | static_cast<int>(__y));
   }
 
+  [[__nodiscard__]]
   constexpr launch operator^(launch __x, launch __y) noexcept
   {
     return static_cast<launch>(
        static_cast<int>(__x) ^ static_cast<int>(__y));
   }
 
+  [[__nodiscard__]]
   constexpr launch operator~(launch __x) noexcept
   { return static_cast<launch>(~static_cast<int>(__x)); }
 
+  _GLIBCXX14_CONSTEXPR
   inline launch& operator&=(launch& __x, launch __y) noexcept
   { return __x = __x & __y; }
 
+  _GLIBCXX14_CONSTEXPR
   inline launch& operator|=(launch& __x, launch __y) noexcept
   { return __x = __x | __y; }
 
+  _GLIBCXX14_CONSTEXPR
   inline launch& operator^=(launch& __x, launch __y) noexcept
   { return __x = __x ^ __y; }
 
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/bitmask_types.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/bitmask_types.cc
new file mode 100644 (file)
index 0000000..aa3d36e
--- /dev/null
@@ -0,0 +1,56 @@
+// { dg-do compile { target c++17 } }
+#include <filesystem>
+
+namespace fs = std::filesystem;
+
+void
+test_copy_options()
+{
+  using T = fs::copy_options;
+  constexpr T val = T::none;
+  constexpr T all = ((val | val) & val) ^ ~val;
+  static_assert( noexcept(((val | val) & val) ^ ~val) );
+  val & val; // { dg-warning "ignoring return value" }
+  val | val; // { dg-warning "ignoring return value" }
+  val ^ val; // { dg-warning "ignoring return value" }
+  ~val;      // { dg-warning "ignoring return value" }
+}
+
+void
+test_perms()
+{
+  using T = fs::perms;
+  constexpr T val = T::none;
+  constexpr T all = ((val | val) & val) ^ ~val;
+  static_assert( noexcept(((val | val) & val) ^ ~val) );
+  val & val; // { dg-warning "ignoring return value" }
+  val | val; // { dg-warning "ignoring return value" }
+  val ^ val; // { dg-warning "ignoring return value" }
+  ~val;      // { dg-warning "ignoring return value" }
+}
+
+void
+test_perm_options()
+{
+  using T = fs::perm_options;
+  constexpr T val = T::replace;
+  constexpr T all = ((val | val) & val) ^ ~val;
+  static_assert( noexcept(((val | val) & val) ^ ~val) );
+  val & val; // { dg-warning "ignoring return value" }
+  val | val; // { dg-warning "ignoring return value" }
+  val ^ val; // { dg-warning "ignoring return value" }
+  ~val;      // { dg-warning "ignoring return value" }
+}
+
+void
+test_directory_options()
+{
+  using T = fs::directory_options;
+  constexpr T val = T::none;
+  constexpr T all = ((val | val) & val) ^ ~val;
+  static_assert( noexcept(((val | val) & val) ^ ~val) );
+  val & val; // { dg-warning "ignoring return value" }
+  val | val; // { dg-warning "ignoring return value" }
+  val ^ val; // { dg-warning "ignoring return value" }
+  ~val;      // { dg-warning "ignoring return value" }
+}
index 64ef31d9cd09797b9e1862df8230d0066280ae32..604d2aa6b5a2675a7e7a9e9d065a7d1471a66137 100644 (file)
@@ -27,3 +27,7 @@ int main()
 {
   __gnu_test::bitmask_operators<std::ios_base::fmtflags>();
 }
+// { dg-warning "ignoring return value.*operator\\|" "" { target c++17 } 0 }
+// { dg-warning "ignoring return value.*operator&" "" { target c++17 } 0 }
+// { dg-warning "ignoring return value.*operator\\^" "" { target c++17 } 0 }
+// { dg-warning "ignoring return value.*operator~" "" { target c++17 } 0 }
index 218cf8b8a9553c6d012f7537ea03865312730a5e..a98435867ed442726ca67d02646210f2d0bd5cbe 100644 (file)
@@ -27,3 +27,7 @@ int main()
 {
   __gnu_test::bitmask_operators<std::ios_base::iostate>();
 }
+// { dg-warning "ignoring return value.*operator\\|" "" { target c++17 } 0 }
+// { dg-warning "ignoring return value.*operator&" "" { target c++17 } 0 }
+// { dg-warning "ignoring return value.*operator\\^" "" { target c++17 } 0 }
+// { dg-warning "ignoring return value.*operator~" "" { target c++17 } 0 }
index b5f1e78167650c3d52efeb9c4e1ef5d571a3ed84..6d02421736288f5533ea413fcf9fa7e1770294fb 100644 (file)
@@ -27,3 +27,7 @@ int main()
 {
   __gnu_test::bitmask_operators<std::ios_base::openmode>();
 }
+// { dg-warning "ignoring return value.*operator\\|" "" { target c++17 } 0 }
+// { dg-warning "ignoring return value.*operator&" "" { target c++17 } 0 }
+// { dg-warning "ignoring return value.*operator\\^" "" { target c++17 } 0 }
+// { dg-warning "ignoring return value.*operator~" "" { target c++17 } 0 }