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 r12-6794] libstdc++: Fix constexpr constructor for atomic<shared_ptr<T>> Date: Fri, 21 Jan 2022 13:21:33 +0000 (GMT) [thread overview] Message-ID: <20220121132133.E134B3857C7D@sourceware.org> (raw) https://gcc.gnu.org/g:7d47aae7cd4bb4dbf1e59a52c2a3f127151c8fab commit r12-6794-g7d47aae7cd4bb4dbf1e59a52c2a3f127151c8fab Author: Jonathan Wakely <jwakely@redhat.com> Date: Fri Jan 21 11:55:22 2022 +0000 libstdc++: Fix constexpr constructor for atomic<shared_ptr<T>> libstdc++-v3/ChangeLog: * include/bits/shared_ptr_atomic.h (_Sp_atomic::_Atomic_count): Add constexpr. (_Sp_atomic::_M_ptr): Add default member-initializer. * testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc: Check constant initialization. * testsuite/20_util/weak_ptr/atomic_weak_ptr.cc: Likewise. Diff: --- libstdc++-v3/include/bits/shared_ptr_atomic.h | 4 ++-- libstdc++-v3/testsuite/20_util/shared_ptr/atomic/atomic_shared_ptr.cc | 3 +++ libstdc++-v3/testsuite/20_util/weak_ptr/atomic_weak_ptr.cc | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/bits/shared_ptr_atomic.h b/libstdc++-v3/include/bits/shared_ptr_atomic.h index 35f781dc9a0..9e4df7da7f8 100644 --- a/libstdc++-v3/include/bits/shared_ptr_atomic.h +++ b/libstdc++-v3/include/bits/shared_ptr_atomic.h @@ -357,7 +357,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Ensure we can use the LSB as the lock bit. static_assert(alignof(remove_pointer_t<pointer>) > 1); - _Atomic_count() : _M_val(0) { } + constexpr _Atomic_count() noexcept = default; explicit _Atomic_count(__count_type&& __c) noexcept @@ -457,7 +457,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static constexpr uintptr_t _S_lock_bit{1}; }; - typename _Tp::element_type* _M_ptr; + typename _Tp::element_type* _M_ptr = nullptr; _Atomic_count _M_refcount; static typename _Atomic_count::pointer 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 725e7ba5031..1f97224bf6a 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 @@ -16,6 +16,9 @@ #include <testsuite_hooks.h> +// Check constexpr constructor. +constinit std::atomic<std::shared_ptr<int>> a; + void test_is_lock_free() { diff --git a/libstdc++-v3/testsuite/20_util/weak_ptr/atomic_weak_ptr.cc b/libstdc++-v3/testsuite/20_util/weak_ptr/atomic_weak_ptr.cc index e394e5562b9..b38cea768c8 100644 --- a/libstdc++-v3/testsuite/20_util/weak_ptr/atomic_weak_ptr.cc +++ b/libstdc++-v3/testsuite/20_util/weak_ptr/atomic_weak_ptr.cc @@ -8,6 +8,9 @@ #include <thread> #include <testsuite_hooks.h> +// Check constexpr constructor. +constinit std::atomic<std::weak_ptr<int>> a; + void test_is_lock_free() {
reply other threads:[~2022-01-21 13:21 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=20220121132133.E134B3857C7D@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: linkBe 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).