]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Deprecate std::atomic_xxx overloads for std::shared_ptr
authorJonathan Wakely <jwakely@redhat.com>
Wed, 8 Nov 2023 13:43:04 +0000 (13:43 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Sat, 11 Nov 2023 00:41:08 +0000 (00:41 +0000)
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
libstdc++-v3/testsuite/20_util/shared_ptr/atomic/1.cc
libstdc++-v3/testsuite/20_util/shared_ptr/atomic/2.cc
libstdc++-v3/testsuite/20_util/shared_ptr/atomic/3.cc
libstdc++-v3/testsuite/29_atomics/atomic/lwg3220.cc

index ae2d1b7a094cc115bc746739393cad8f2ded79d5..5b818fe4456829adac77003593d373983d785f26 100644 (file)
@@ -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,
index e9fb8d0f3292c642cf3ad4877ae8c338d09683de..b5225f8a0dfb12398f4919e40489e1ce2baafa62 100644 (file)
@@ -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>
 
index 778f132d33a4aeec03f2952bcfcfa73511e4cf04..f8412fe1eb1f1c73824acef241b1f691788ca3e9 100644 (file)
@@ -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>
 
index 19efcadb7ec4ae5643b7968988e6112d2d003d03..6c5bad1e094ecad4cf45eb72b220ac86a1934325 100644 (file)
@@ -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.
 //
index ba289e197dca35132e6832fd9f04c969880aa8d1..217db7cbfeafa46fca359fb25833d8ff5c4d5971 100644 (file)
@@ -1,3 +1,4 @@
+// { dg-options "-Wno-deprecated" }
 // { dg-do compile { target c++11 } }
 
 // std::shared_ptr is not freestanding.