From 60d0d6b24fc533b349f8de082a8bbd819c8c31bd Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 24 Nov 2020 00:07:37 -0800 Subject: [PATCH 1/3] Fix atomic_ref's static_assert. --- stl/inc/atomic | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) 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; From 27bbf9720883be4c44b24fa26432ea6be558735a Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 24 Nov 2020 00:43:07 -0800 Subject: [PATCH 2/3] Test atomic_ref. --- tests/std/tests/P0019R8_atomic_ref/test.cpp | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/std/tests/P0019R8_atomic_ref/test.cpp b/tests/std/tests/P0019R8_atomic_ref/test.cpp index 1813049d209..91e9ee013b3 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 int ci{1729}; + 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(); } From 9a2d3413facef9b51a57538de6341026532d7871 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Mon, 30 Nov 2020 17:50:13 -0800 Subject: [PATCH 3/3] Code review feedback. --- tests/std/tests/P0019R8_atomic_ref/test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/std/tests/P0019R8_atomic_ref/test.cpp b/tests/std/tests/P0019R8_atomic_ref/test.cpp index 91e9ee013b3..d8398df7f76 100644 --- a/tests/std/tests/P0019R8_atomic_ref/test.cpp +++ b/tests/std/tests/P0019R8_atomic_ref/test.cpp @@ -270,9 +270,9 @@ void test_ptr_ops() { } // GH-1497 : atomic_ref fails to compile -void test_gh_1497() { +void test_gh_1497_const_type() { { - const int ci{1729}; + 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); } @@ -340,5 +340,5 @@ int main() { test_ptr_ops(); test_ptr_ops(); - test_gh_1497(); + test_gh_1497_const_type(); }