diff mbox series

[committed] libstdc++: Deprecate std::atomic_xxx overloads for std::shared_ptr

Message ID 20231111004453.78040-1-jwakely@redhat.com
State New
Headers show
Series [committed] libstdc++: Deprecate std::atomic_xxx overloads for std::shared_ptr | expand

Commit Message

Jonathan Wakely Nov. 11, 2023, 12:44 a.m. UTC
Tested x86_64-linux. Pushed to trunk.

-- >8 --

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.
---
 libstdc++-v3/include/bits/shared_ptr_atomic.h | 22 +++++++++++++++++++
 .../testsuite/20_util/shared_ptr/atomic/1.cc  |  1 +
 .../testsuite/20_util/shared_ptr/atomic/2.cc  |  1 +
 .../testsuite/20_util/shared_ptr/atomic/3.cc  |  1 +
 .../testsuite/29_atomics/atomic/lwg3220.cc    |  1 +
 5 files changed, 26 insertions(+)
diff mbox series

Patch

diff --git a/libstdc++-v3/include/bits/shared_ptr_atomic.h b/libstdc++-v3/include/bits/shared_ptr_atomic.h
index ae2d1b7a094..5b818fe4456 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 e9fb8d0f329..b5225f8a0df 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 778f132d33a..f8412fe1eb1 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 19efcadb7ec..6c5bad1e094 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 ba289e197dc..217db7cbfea 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.