Skip to content

Commit 9a85476

Browse files
Implement LWG-3893 LWG-3661 broke atomic<shared_ptr<T>> a; a = nullptr; (#3782)
1 parent 1b532be commit 9a85476

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

stl/inc/memory

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4003,6 +4003,10 @@ public:
40034003
store(_STD move(_Value));
40044004
}
40054005

4006+
void operator=(nullptr_t) noexcept {
4007+
store(nullptr);
4008+
}
4009+
40064010
~atomic() {
40074011
const auto _Rep = this->_Repptr._Unsafe_load_relaxed();
40084012
if (_Rep) {

tests/std/tests/P0718R2_atomic_smart_ptrs/test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

44
#include <cassert>
5+
#include <cstddef>
56
#include <cstdint>
67
#include <memory>
78
#include <thread>
9+
#include <type_traits>
810
#ifdef _DEBUG
911
#include <crtdbg.h>
1012
#endif // _DEBUG
@@ -632,6 +634,13 @@ int main() {
632634
ensure_member_calls_compile<atomic<shared_ptr<int[2][2]>>>();
633635
ensure_member_calls_compile<atomic<weak_ptr<int[2][2]>>>();
634636

637+
// LWG-3893: LWG 3661 broke atomic<shared_ptr<T>> a; a = nullptr;
638+
static_assert(is_nothrow_assignable_v<atomic<shared_ptr<bool>>, nullptr_t>);
639+
static_assert(is_nothrow_assignable_v<atomic<shared_ptr<int>>, nullptr_t>);
640+
static_assert(is_nothrow_assignable_v<atomic<shared_ptr<int[]>>, nullptr_t>);
641+
static_assert(is_nothrow_assignable_v<atomic<shared_ptr<int[][2]>>, nullptr_t>);
642+
static_assert(is_nothrow_assignable_v<atomic<shared_ptr<int[2][2]>>, nullptr_t>);
643+
635644
#ifdef _DEBUG
636645
sptr0 = {};
637646
sptr1 = {};

0 commit comments

Comments
 (0)