]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Deprecate std::memory_order::consume
authorJonathan Wakely <jwakely@redhat.com>
Thu, 21 May 2026 16:09:47 +0000 (17:09 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 26 May 2026 10:13:59 +0000 (11:13 +0100)
This implements P3475R2, "Defang and deprecate memory_order::consume",
approved in Hagenberg, 2025.

It looks like the using-declaration for memory_order_consume in
<stdatomic.h> was not deprecated by the paper, but I don't think we can
implement that if we warn for the name in <atomic>. It doesn't make
sense to me for it to be deprecated in C++ but still usable in the C/C++
compatibility header. It's still just as useless in common C/C++
headers, so we should warn.

libstdc++-v3/ChangeLog:

* include/bits/atomic_base.h (memory_order::consume): Add
deprecate attribute.
(memory_order_consume): Likewise.
(kill_dependency): Likewise.
(atomic_flag::clear): Disable warning with pragmas.
(__atomic_base::store, __atomic_base<T*>::store): Likewise.
* include/c_compatibility/stdatomic.h (memory_order_consume):
Likewise.
* testsuite/29_atomics/atomic/requirements/compare_exchange_lowering.cc:
Ignore deprecation warnings.
* testsuite/29_atomics/atomic_flag/test_and_set/explicit-hle.cc:
Likewise.
* testsuite/29_atomics/headers/atomic/types_std_c++0x.cc: Add
dg-warning directives.
* testsuite/29_atomics/headers/stdatomic.h/c_compat.cc:
Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/warn/Winvalid-memory-model-2.C: Disable deprecated
warnings for C++26 and up.
* g++.dg/warn/Winvalid-memory-model.C: Likewise.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
gcc/testsuite/g++.dg/warn/Winvalid-memory-model-2.C
gcc/testsuite/g++.dg/warn/Winvalid-memory-model.C
libstdc++-v3/include/bits/atomic_base.h
libstdc++-v3/include/c_compatibility/stdatomic.h
libstdc++-v3/testsuite/29_atomics/atomic/requirements/compare_exchange_lowering.cc
libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit-hle.cc
libstdc++-v3/testsuite/29_atomics/headers/atomic/types_std_c++0x.cc
libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/c_compat.cc

index a15706159aafacb28706f89a612c76d4ee0b0105..05d5c4eda21de4f6c35907d8cd6989a62d3ba331 100644 (file)
@@ -2,7 +2,8 @@
    -Wsystem-headers
    Verify warnings for atomic functions with optimization.
    { dg-do compile { target c++11 } }
-   { dg-options "-O1" } */
+   { dg-options "-O1" }
+   { dg-additional-options "-Wno-deprecated-declarations" { target c++26 } } */
 
 #include <atomic>
 
index 0ef2c75dee76fabe178a26a33cd91f49cb30a91e..509ce280534c1b19e866233d3c180bd7a92db158 100644 (file)
@@ -2,7 +2,8 @@
    -Wsystem-headers
    Verify warnings for basic atomic functions with no optimization.
    { dg-do compile { target c++11 } }
-   { dg-options "-O0 -Wall" } */
+   { dg-options "-O0 -Wall" }
+   { dg-additional-options "-Wno-deprecated-declarations" { target c++26 } } */
 
 #include <atomic>
 
index e9cf174e46077c12ae498abc1f5d2e9c0f53a818..3a8e9a7b4c1f659a8b895a1235f0eebd273cab8b 100644 (file)
@@ -64,20 +64,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #if __cplusplus > 201703L
   enum class memory_order : int
     {
-      relaxed,
-      consume,
-      acquire,
-      release,
-      acq_rel,
-      seq_cst
+      relaxed = 0,
+      consume _GLIBCXX26_DEPRECATED = 1,
+      acquire = 2,
+      release = 3,
+      acq_rel = 4,
+      seq_cst = 5
     };
 
   inline constexpr memory_order memory_order_relaxed = memory_order::relaxed;
-  inline constexpr memory_order memory_order_consume = memory_order::consume;
   inline constexpr memory_order memory_order_acquire = memory_order::acquire;
   inline constexpr memory_order memory_order_release = memory_order::release;
   inline constexpr memory_order memory_order_acq_rel = memory_order::acq_rel;
   inline constexpr memory_order memory_order_seq_cst = memory_order::seq_cst;
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+  _GLIBCXX26_DEPRECATED
+  inline constexpr memory_order memory_order_consume = memory_order::consume;
+#pragma GCC diagnostic pop
 #else
   enum memory_order : int
     {
@@ -152,6 +157,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// kill_dependency
   template<typename _Tp>
+    _GLIBCXX26_DEPRECATED
     inline _Tp
     kill_dependency(_Tp __y) noexcept
     {
@@ -278,6 +284,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     // TODO add const volatile overload
 #endif // __glibcxx_atomic_wait
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
     _GLIBCXX_ALWAYS_INLINE void
     clear(memory_order __m = memory_order_seq_cst) noexcept
     {
@@ -301,6 +309,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       __atomic_clear (&_M_i, int(__m));
     }
+#pragma GCC diagnostic pop
 
   private:
     static constexpr __atomic_flag_data_type
@@ -482,6 +491,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
            reinterpret_cast<void *>(-_S_alignment));
       }
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
       _GLIBCXX_ALWAYS_INLINE void
       store(__int_type __i, memory_order __m = memory_order_seq_cst) noexcept
       {
@@ -506,6 +517,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
        __atomic_store_n(&_M_i, __i, int(__m));
       }
+#pragma GCC diagnostic pop
 
       _GLIBCXX_ALWAYS_INLINE __int_type
       load(memory_order __m = memory_order_seq_cst) const noexcept
@@ -831,6 +843,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
            reinterpret_cast<void *>(-__alignof(_M_p)));
       }
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
       _GLIBCXX_ALWAYS_INLINE void
       store(__pointer_type __p,
            memory_order __m = memory_order_seq_cst) noexcept
@@ -857,6 +871,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
        __atomic_store_n(&_M_p, __p, int(__m));
       }
+#pragma GCC diagnostic pop
 
       _GLIBCXX_ALWAYS_INLINE __pointer_type
       load(memory_order __m = memory_order_seq_cst) const noexcept
index 72b9446eb170abf15937f17255236fdeda007840..c118d880bac3f66b7ef483eb00af0ae8fc73267b 100644 (file)
 
 using std::memory_order;
 using std::memory_order_relaxed;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 using std::memory_order_consume;
+#pragma GCC diagnostic pop
 using std::memory_order_acquire;
 using std::memory_order_release;
 using std::memory_order_acq_rel;
index fa69558e7239ec0e07482a01ef3a6d8b7f25e94a..089e4bdf48d073692abd443b1b9721cc38b9b89e 100644 (file)
@@ -20,6 +20,8 @@
 #include <atomic>
 #include <testsuite_common_types.h>
 
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
 #define TEST_ALL_ORDERS()                       \
   do {                                          \
     ORDER_TEST(std::memory_order_relaxed);      \
index 587e3eea127d397fbb072880b1debf68cc7413da..f7bccfe498d50143005de01fd9d01ceb7a0cbefc 100644 (file)
@@ -25,6 +25,8 @@
 
 #include <atomic>
 
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
 const auto ACQ = std::memory_order_acquire | std::__memory_order_hle_acquire;
 const auto REL = std::memory_order_release | std::__memory_order_hle_release;
 
index 2b0685345c338f8023b7e9cf7c1b634017a7ff98..ce6e0728c4bc555232f76359753f033bcccf5586 100644 (file)
@@ -33,7 +33,7 @@ void test01()
 #if __cplusplus >= 202002L
   using std::memory_order;
   constexpr auto relaxed = memory_order::relaxed;
-  constexpr auto consume = memory_order::consume;
+  constexpr auto consume = memory_order::consume; // { dg-warning "deprecated" "" { target c++26 } }
   constexpr auto acquire = memory_order::acquire;
   constexpr auto release = memory_order::release;
   constexpr auto acq_rel = memory_order::acq_rel;
index bcdb969b0c0f0fc128644916110dcfc2cc015dec..ed980a50b353c5bf9e4af1e4838c45b24a48b37b 100644 (file)
@@ -41,7 +41,9 @@
 #endif
 
 constexpr const memory_order* orders[] = {
-  &memory_order_relaxed, &memory_order_consume, &memory_order_acquire,
+  &memory_order_relaxed,
+  &memory_order_consume, // { dg-warning "deprecated" "" { target c++26 } }
+  &memory_order_acquire,
   &memory_order_release, &memory_order_acq_rel, &memory_order_seq_cst
 };