diff --git a/stl/inc/atomic b/stl/inc/atomic index 8dfadf62917..077c8a5dd1b 100644 --- a/stl/inc/atomic +++ b/stl/inc/atomic @@ -2346,12 +2346,7 @@ private: using _Base = _Choose_atomic_base_t<_Ty, _Ty&>; public: - // clang-format off - static_assert(is_trivially_copyable_v<_Ty> && is_copy_constructible_v<_Ty> && is_move_constructible_v<_Ty> - && is_copy_assignable_v<_Ty> && is_move_assignable_v<_Ty>, - "atomic_ref requires T to be trivially copyable, copy constructible, move constructible, copy assignable, " - "and move assignable."); - // clang-format on + static_assert(is_trivially_copyable_v<_Ty>, "atomic_ref requires T to be trivially copyable."); using value_type = _Ty; diff --git a/tests/std/tests/P0019R8_atomic_ref/test.cpp b/tests/std/tests/P0019R8_atomic_ref/test.cpp index 1813049d209..d8398df7f76 100644 --- a/tests/std/tests/P0019R8_atomic_ref/test.cpp +++ b/tests/std/tests/P0019R8_atomic_ref/test.cpp @@ -269,6 +269,26 @@ void test_ptr_ops() { assert(ry.load() == a + 0x10); } +// GH-1497 : atomic_ref fails to compile +void test_gh_1497_const_type() { + { + static constexpr int ci{1729}; // static storage duration, so this is stored in read-only memory + const std::atomic_ref atom{ci}; + assert(atom.load() == 1729); + } + + { + int i{11}; + const std::atomic_ref atom_modify{i}; + const std::atomic_ref atom_observe{i}; + assert(atom_modify.load() == 11); + assert(atom_observe.load() == 11); + atom_modify.store(22); + assert(atom_modify.load() == 22); + assert(atom_observe.load() == 22); + } +} + int main() { test_ops(); test_ops(); @@ -319,4 +339,6 @@ int main() { test_ptr_ops(); test_ptr_ops(); + + test_gh_1497_const_type(); }