diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2023-11-08 13:43:04 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2023-11-11 00:41:08 +0000 |
commit | 090589e84b04753a1bc99cdeeaadaf361555cb83 (patch) | |
tree | 327f97e6f5751a71ed7fb85c3a4003e6166b32f8 | |
parent | 64bcf3f07a211f2ea136d99b3700c172efc08d93 (diff) | |
download | gcc-090589e84b04753a1bc99cdeeaadaf361555cb83.zip gcc-090589e84b04753a1bc99cdeeaadaf361555cb83.tar.gz gcc-090589e84b04753a1bc99cdeeaadaf361555cb83.tar.bz2 |
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<std::shared_ptr<T>> 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.
5 files changed, 26 insertions, 0 deletions
diff --git a/libstdc++-v3/include/bits/shared_ptr_atomic.h b/libstdc++-v3/include/bits/shared_ptr_atomic.h index ae2d1b7..5b818fe 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<typename _Tp, _Lock_policy _Lp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") inline bool atomic_is_lock_free(const __shared_ptr<_Tp, _Lp>*) { @@ -112,6 +113,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Tp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") 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<typename _Tp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") inline shared_ptr<_Tp> atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order) { @@ -136,11 +139,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Tp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") inline shared_ptr<_Tp> atomic_load(const shared_ptr<_Tp>* __p) { return std::atomic_load_explicit(__p, memory_order_seq_cst); } template<typename _Tp, _Lock_policy _Lp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") 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<typename _Tp, _Lock_policy _Lp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") 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<typename _Tp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") inline void atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order) @@ -173,11 +180,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Tp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") 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<typename _Tp, _Lock_policy _Lp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") inline void atomic_store_explicit(__shared_ptr<_Tp, _Lp>* __p, __shared_ptr<_Tp, _Lp> __r, @@ -188,6 +197,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Tp, _Lock_policy _Lp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") 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<typename _Tp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") 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<typename _Tp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") inline shared_ptr<_Tp> atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r) { @@ -219,6 +231,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Tp, _Lock_policy _Lp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") 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<typename _Tp, _Lock_policy _Lp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") 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<typename _Tp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") bool atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, @@ -272,6 +287,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Tp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") 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<typename _Tp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") inline bool atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, @@ -293,6 +310,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } template<typename _Tp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") 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<typename _Tp, _Lock_policy _Lp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") 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<typename _Tp, _Lock_policy _Lp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") 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<typename _Tp, _Lock_policy _Lp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") 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<typename _Tp, _Lock_policy _Lp> + _GLIBCXX20_DEPRECATED_SUGGEST("std::atomic<std::shared_ptr<T>>") 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 e9fb8d0..b5225f8 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 <memory> 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 778f132..f8412fe 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 <memory> 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 19efcad..6c5bad1 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 ba289e1..217db7c 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. |