]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix assigning nullptr to std::atomic<shared_ptr<T>> (LWG 3893)
authorJonathan Wakely <jwakely@redhat.com>
Wed, 22 Mar 2023 21:54:24 +0000 (21:54 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 20 Apr 2023 11:27:01 +0000 (12:27 +0100)
LWG voted this to Tentatively Ready recently.

libstdc++-v3/ChangeLog:

* include/bits/shared_ptr_atomic.h (atomic::operator=(nullptr_t)):
Add overload, as per LWG 3893.
* testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc:
Check assignment from nullptr.

(cherry picked from commit a495b738e4a89a8104798d005fd09474bbb916ff)

libstdc++-v3/include/bits/shared_ptr_atomic.h
libstdc++-v3/testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc

index 7f30d0ac008d164cfe823806ed31364ba94b75c4..94570cd3ab3c90bf7e6f28949f169cd6a482ee78 100644 (file)
@@ -642,6 +642,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       operator=(shared_ptr<_Tp> __desired) noexcept
       { _M_impl.swap(__desired, memory_order_seq_cst); }
 
+      // _GLIBCXX_RESOLVE_LIB_DEFECTS
+      // 3893. LWG 3661 broke atomic<shared_ptr<T>> a; a = nullptr;
+      void
+      operator=(nullptr_t) noexcept
+      { store(nullptr); }
+
       shared_ptr<_Tp>
       exchange(shared_ptr<_Tp> __desired,
               memory_order __o = memory_order_seq_cst) noexcept
index a1902745a3ef4ae9452846d472a8a52817493ac1..54cf2621ea1d26ea3e9d7e1c977834306ea0ef0d 100644 (file)
@@ -145,6 +145,14 @@ test_counting()
   VERIFY( counter == 2 );
 }
 
+void
+test_lwg3893()
+{
+  // LWG 3893. LWG 3661 broke atomic<shared_ptr<T>> a; a = nullptr;
+  std::atomic<std::shared_ptr<int>> a;
+  a = nullptr;
+}
+
 int
 main()
 {
@@ -152,4 +160,5 @@ main()
   test_atomic_shared_ptr();
   test_wait_notify();
   test_counting();
+  test_lwg3893();
 }