From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Fix assigning nullptr to std::atomic<shared_ptr<T>> (LWG 3893)
Date: Wed, 22 Mar 2023 23:27:09 +0000 [thread overview]
Message-ID: <20230322232709.457972-1-jwakely@redhat.com> (raw)
Tested powerpc64le-linux. Pushed to trunk.
-- >8 --
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.
---
libstdc++-v3/include/bits/shared_ptr_atomic.h | 6 ++++++
.../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();
}
--
2.39.2
reply other threads:[~2023-03-22 23:27 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=20230322232709.457972-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@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).