From: Jonathan Wakely Date: Wed, 22 Mar 2023 21:54:24 +0000 (+0000) Subject: libstdc++: Fix assigning nullptr to std::atomic> (LWG 3893) X-Git-Tag: upstream/13.1.0~428 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a495b738e4a89a8104798d005fd09474bbb916ff;p=platform%2Fupstream%2Fgcc.git libstdc++: Fix assigning nullptr to std::atomic> (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 --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> 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> a; a = nullptr; + std::atomic> a; + a = nullptr; +} + int main() { @@ -152,4 +160,5 @@ main() test_atomic_shared_ptr(); test_wait_notify(); test_counting(); + test_lwg3893(); }