public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6816] libstdc++: Fix assigning nullptr to std::atomic<shared_ptr<T>> (LWG 3893)
@ 2023-03-22 23:26 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-03-22 23:26 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:a495b738e4a89a8104798d005fd09474bbb916ff

commit r13-6816-ga495b738e4a89a8104798d005fd09474bbb916ff
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Mar 22 21:54:24 2023 +0000

    libstdc++: Fix assigning nullptr to std::atomic<shared_ptr<T>> (LWG 3893)
    
    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.

Diff:
---
 libstdc++-v3/include/bits/shared_ptr_atomic.h                    | 6 ++++++
 .../testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc     | 9 +++++++++
 2 files changed, 15 insertions(+)

diff --git a/libstdc++-v3/include/bits/shared_ptr_atomic.h b/libstdc++-v3/include/bits/shared_ptr_atomic.h
index d142616f485..2295b48e732 100644
--- a/libstdc++-v3/include/bits/shared_ptr_atomic.h
+++ b/libstdc++-v3/include/bits/shared_ptr_atomic.h
@@ -650,6 +650,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
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc
index a1902745a3e..54cf2621ea1 100644
--- a/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc
@@ -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();
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-22 23:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-22 23:26 [gcc r13-6816] libstdc++: Fix assigning nullptr to std::atomic<shared_ptr<T>> (LWG 3893) Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).