From: Jonathan Wakely Date: Wed, 8 Nov 2023 13:43:04 +0000 (+0000) Subject: libstdc++: Deprecate std::atomic_xxx overloads for std::shared_ptr X-Git-Tag: basepoints/gcc-15~4794 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=090589e84b04753a1bc99cdeeaadaf361555cb83;p=thirdparty%2Fgcc.git libstdc++: Deprecate std::atomic_xxx overloads for std::shared_ptr These overloads are deprecated in C++20 (and likely to be removed for C++26). The std::atomic> specialization should be preferred in new code. libstdc++-v3/ChangeLog: * include/bits/shared_ptr_atomic.h (atomic_is_lock_free) (atomic_load_explicit, atomic_load, atomic_store_explicit) (atomic_store, atomic_exchange_explicit, atomic_exchange) (atomic_compare_exchange_strong, atomic_compare_exchange_weak) (atomic_compare_exchange_strong_explicit) (atomic_compare_exchange_weak_explicit): Add deprecated attribute for C++20 and later. * testsuite/20_util/shared_ptr/atomic/1.cc: Suppress deprecated warnings. * testsuite/20_util/shared_ptr/atomic/2.cc: Likewise. * testsuite/20_util/shared_ptr/atomic/3.cc: Likewise. * testsuite/29_atomics/atomic/lwg3220.cc: Likewise. --- diff --git a/libstdc++-v3/include/bits/shared_ptr_atomic.h b/libstdc++-v3/include/bits/shared_ptr_atomic.h index ae2d1b7a094c..5b818fe44568 100644 --- a/libstdc++-v3/include/bits/shared_ptr_atomic.h +++ b/libstdc++-v3/include/bits/shared_ptr_atomic.h @@ -101,6 +101,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @{ */ template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline bool atomic_is_lock_free(const __shared_ptr<_Tp, _Lp>*) { @@ -112,6 +113,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline bool atomic_is_lock_free(const shared_ptr<_Tp>* __p) { return std::atomic_is_lock_free<_Tp, __default_lock_policy>(__p); } @@ -128,6 +130,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @{ */ template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline shared_ptr<_Tp> atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order) { @@ -136,11 +139,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline shared_ptr<_Tp> atomic_load(const shared_ptr<_Tp>* __p) { return std::atomic_load_explicit(__p, memory_order_seq_cst); } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline __shared_ptr<_Tp, _Lp> atomic_load_explicit(const __shared_ptr<_Tp, _Lp>* __p, memory_order) { @@ -149,6 +154,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline __shared_ptr<_Tp, _Lp> atomic_load(const __shared_ptr<_Tp, _Lp>* __p) { return std::atomic_load_explicit(__p, memory_order_seq_cst); } @@ -164,6 +170,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @{ */ template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline void atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) @@ -173,11 +180,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline void atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) { std::atomic_store_explicit(__p, std::move(__r), memory_order_seq_cst); } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline void atomic_store_explicit(__shared_ptr<_Tp, _Lp>* __p, __shared_ptr<_Tp, _Lp> __r, @@ -188,6 +197,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline void atomic_store(__shared_ptr<_Tp, _Lp>* __p, __shared_ptr<_Tp, _Lp> __r) { std::atomic_store_explicit(__p, std::move(__r), memory_order_seq_cst); } @@ -201,6 +211,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @{ */ template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline shared_ptr<_Tp> atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) @@ -211,6 +222,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline shared_ptr<_Tp> atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) { @@ -219,6 +231,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline __shared_ptr<_Tp, _Lp> atomic_exchange_explicit(__shared_ptr<_Tp, _Lp>* __p, __shared_ptr<_Tp, _Lp> __r, @@ -230,6 +243,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline __shared_ptr<_Tp, _Lp> atomic_exchange(__shared_ptr<_Tp, _Lp>* __p, __shared_ptr<_Tp, _Lp> __r) { @@ -250,6 +264,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @{ */ template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") bool atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, @@ -272,6 +287,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline bool atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) @@ -281,6 +297,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline bool atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, @@ -293,6 +310,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline bool atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w) @@ -302,6 +320,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") bool atomic_compare_exchange_strong_explicit(__shared_ptr<_Tp, _Lp>* __p, __shared_ptr<_Tp, _Lp>* __v, @@ -324,6 +343,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline bool atomic_compare_exchange_strong(__shared_ptr<_Tp, _Lp>* __p, __shared_ptr<_Tp, _Lp>* __v, @@ -334,6 +354,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline bool atomic_compare_exchange_weak_explicit(__shared_ptr<_Tp, _Lp>* __p, __shared_ptr<_Tp, _Lp>* __v, @@ -346,6 +367,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic>") inline bool atomic_compare_exchange_weak(__shared_ptr<_Tp, _Lp>* __p, __shared_ptr<_Tp, _Lp>* __v, diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/1.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/1.cc index e9fb8d0f3292..b5225f8a0dfb 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/1.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/1.cc @@ -18,6 +18,7 @@ // { dg-do run { target c++11 } } // { dg-require-gthreads "" } // { dg-require-effective-target hosted } +// { dg-additional-options "-Wno-deprecated" { target c++20 } } #include diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/2.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/2.cc index 778f132d33a4..f8412fe1eb1f 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/2.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/2.cc @@ -18,6 +18,7 @@ // { dg-do run { target c++11 } } // { dg-require-gthreads "" } // { dg-require-effective-target hosted } +// { dg-additional-options "-Wno-deprecated" { target c++20 } } #include diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/3.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/3.cc index 19efcadb7ec4..6c5bad1e094e 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/3.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/3.cc @@ -1,6 +1,7 @@ // { dg-do run { target c++11 } } // { dg-additional-options "-pthread" { target pthread } } // { dg-require-gthreads "" } +// { dg-additional-options "-Wno-deprecated" { target c++20 } } // Copyright (C) 2014-2023 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/lwg3220.cc b/libstdc++-v3/testsuite/29_atomics/atomic/lwg3220.cc index ba289e197dca..217db7cbfeaf 100644 --- a/libstdc++-v3/testsuite/29_atomics/atomic/lwg3220.cc +++ b/libstdc++-v3/testsuite/29_atomics/atomic/lwg3220.cc @@ -1,3 +1,4 @@ +// { dg-options "-Wno-deprecated" } // { dg-do compile { target c++11 } } // std::shared_ptr is not freestanding.