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.
This commit is contained in:
Jonathan Wakely 2023-03-22 21:54:24 +00:00
parent 6b2740946d
commit a495b738e4
2 changed files with 15 additions and 0 deletions

View file

@ -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

View file

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