Skip to content

Commit

Permalink
Implement LWG-3893 LWG-3661 broke `atomic<shared_ptr<T>> a; a = nullp…
Browse files Browse the repository at this point in the history
…tr;` (#3782)
  • Loading branch information
frederick-vs-ja authored Jun 22, 2023
1 parent 1b532be commit 9a85476
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions stl/inc/memory
Original file line number Diff line number Diff line change
Expand Up @@ -4003,6 +4003,10 @@ public:
store(_STD move(_Value));
}

void operator=(nullptr_t) noexcept {
store(nullptr);
}

~atomic() {
const auto _Rep = this->_Repptr._Unsafe_load_relaxed();
if (_Rep) {
Expand Down
9 changes: 9 additions & 0 deletions tests/std/tests/P0718R2_atomic_smart_ptrs/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <cassert>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <thread>
#include <type_traits>
#ifdef _DEBUG
#include <crtdbg.h>
#endif // _DEBUG
Expand Down Expand Up @@ -632,6 +634,13 @@ int main() {
ensure_member_calls_compile<atomic<shared_ptr<int[2][2]>>>();
ensure_member_calls_compile<atomic<weak_ptr<int[2][2]>>>();

// LWG-3893: LWG 3661 broke atomic<shared_ptr<T>> a; a = nullptr;
static_assert(is_nothrow_assignable_v<atomic<shared_ptr<bool>>, nullptr_t>);
static_assert(is_nothrow_assignable_v<atomic<shared_ptr<int>>, nullptr_t>);
static_assert(is_nothrow_assignable_v<atomic<shared_ptr<int[]>>, nullptr_t>);
static_assert(is_nothrow_assignable_v<atomic<shared_ptr<int[][2]>>, nullptr_t>);
static_assert(is_nothrow_assignable_v<atomic<shared_ptr<int[2][2]>>, nullptr_t>);

#ifdef _DEBUG
sptr0 = {};
sptr1 = {};
Expand Down

0 comments on commit 9a85476

Please sign in to comment.