libstdc++: Fix constexpr constructor for atomic<shared_ptr<T>>
authorJonathan Wakely <jwakely@redhat.com>
Fri, 21 Jan 2022 11:55:22 +0000 (11:55 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 21 Jan 2022 13:21:27 +0000 (13:21 +0000)
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.

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

index 35f781d..9e4df7d 100644 (file)
@@ -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
index 725e7ba..1f97224 100644 (file)
@@ -16,6 +16,9 @@
 
 #include <testsuite_hooks.h>
 
+// Check constexpr constructor.
+constinit std::atomic<std::shared_ptr<int>> a;
+
 void
 test_is_lock_free()
 {
index e394e55..b38cea7 100644 (file)
@@ -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()
 {