On Fri, May 22, 2026 at 1:41 AM Jonathan Wakely <[email protected]> wrote:
> 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.
> ---
>
> Tested x86_64-linux.
>
LGTM. I wondered about putting diagnostic pop and push pragmas just around
consume
use, but that will duplicate they count.
>
> libstdc++-v3/include/bits/atomic_base.h | 29 ++++++++++++++-----
> .../include/c_compatibility/stdatomic.h | 3 ++
> .../requirements/compare_exchange_lowering.cc | 2 ++
> .../atomic_flag/test_and_set/explicit-hle.cc | 2 ++
> .../headers/atomic/types_std_c++0x.cc | 2 +-
> .../headers/stdatomic.h/c_compat.cc | 4 ++-
> 6 files changed, 33 insertions(+), 9 deletions(-)
>
> diff --git a/libstdc++-v3/include/bits/atomic_base.h
> b/libstdc++-v3/include/bits/atomic_base.h
> index e9cf174e4607..3a8e9a7b4c1f 100644
> --- a/libstdc++-v3/include/bits/atomic_base.h
> +++ b/libstdc++-v3/include/bits/atomic_base.h
> @@ -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
> diff --git a/libstdc++-v3/include/c_compatibility/stdatomic.h
> b/libstdc++-v3/include/c_compatibility/stdatomic.h
> index 72b9446eb170..c118d880bac3 100644
> --- a/libstdc++-v3/include/c_compatibility/stdatomic.h
> +++ b/libstdc++-v3/include/c_compatibility/stdatomic.h
> @@ -39,7 +39,10 @@
>
> 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;
> diff --git
> a/libstdc++-v3/testsuite/29_atomics/atomic/requirements/compare_exchange_lowering.cc
> b/libstdc++-v3/testsuite/29_atomics/atomic/requirements/compare_exchange_lowering.cc
> index fa69558e7239..089e4bdf48d0 100644
> ---
> a/libstdc++-v3/testsuite/29_atomics/atomic/requirements/compare_exchange_lowering.cc
> +++
> b/libstdc++-v3/testsuite/29_atomics/atomic/requirements/compare_exchange_lowering.cc
> @@ -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); \
> diff --git
> a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit-hle.cc
> b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit-hle.cc
> index 587e3eea127d..f7bccfe498d5 100644
> ---
> a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit-hle.cc
> +++
> b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit-hle.cc
> @@ -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;
>
> diff --git
> a/libstdc++-v3/testsuite/29_atomics/headers/atomic/types_std_c++0x.cc
> b/libstdc++-v3/testsuite/29_atomics/headers/atomic/types_std_c++0x.cc
> index 2b0685345c33..ce6e0728c4bc 100644
> --- a/libstdc++-v3/testsuite/29_atomics/headers/atomic/types_std_c++0x.cc
> +++ b/libstdc++-v3/testsuite/29_atomics/headers/atomic/types_std_c++0x.cc
> @@ -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;
> diff --git
> a/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/c_compat.cc
> b/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/c_compat.cc
> index bcdb969b0c0f..ed980a50b353 100644
> --- a/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/c_compat.cc
> +++ b/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/c_compat.cc
> @@ -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
> };
>
> --
> 2.54.0
>
>