public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r13-6816] libstdc++: Fix assigning nullptr to std::atomic<shared_ptr<T>> (LWG 3893)
Date: Wed, 22 Mar 2023 23:26:55 +0000 (GMT)	[thread overview]
Message-ID: <20230322232655.303283858436@sourceware.org> (raw)

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();
 }

                 reply	other threads:[~2023-03-22 23:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230322232655.303283858436@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).