Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement LWG-4169 std::atomic<T>'s default constructor should be constrained #5128

Merged
merged 5 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions stl/inc/atomic
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,7 @@ public:

using _Base::_Base;

template <class _Uty = _Ty, enable_if_t<is_default_constructible_v<_Uty>, int> = 0>
constexpr atomic() noexcept(is_nothrow_default_constructible_v<_Ty>) : _Base() {}

atomic(const atomic&) = delete;
Expand Down Expand Up @@ -2803,9 +2804,17 @@ _EXPORT_STD struct atomic_flag { // flag with test-and-set semantics
#endif // _HAS_CXX20

#if 1 // TRANSITION, ABI
atomic<long> _Storage;
atomic<long> _Storage
#if !_HAS_CXX20 && defined(__EDG__)
frederick-vs-ja marked this conversation as resolved.
Show resolved Hide resolved
{0L}
#endif // ^^^ workaround ^^^
;
#else // ^^^ don't break ABI / break ABI vvv
atomic<bool> _Storage;
atomic<bool> _Storage
#if !_HAS_CXX20 && defined(__EDG__)
{false}
#endif // ^^^ workaround ^^^
;
#endif // ^^^ break ABI ^^^
};

Expand Down
13 changes: 12 additions & 1 deletion tests/std/tests/Dev11_0863628_atomic_compare_exchange/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <limits>
#include <new>
#include <type_traits>


using namespace std;

#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
Expand Down Expand Up @@ -438,6 +438,17 @@ STATIC_ASSERT(atomic<void*>::is_always_lock_free);
STATIC_ASSERT(atomic<int (*)(int)>::is_always_lock_free);
#endif // _HAS_CXX17

// Also test LWG-4169 std::atomic<T>'s default constructor should be constrained
// (backported to C++14/17 modes as we backported P0883R2)
STATIC_ASSERT(is_default_constructible_v<atomic<int>>);
STATIC_ASSERT(is_default_constructible_v<atomic<bool>>);
STATIC_ASSERT(is_default_constructible_v<atomic<void*>>);
STATIC_ASSERT(is_default_constructible_v<atomic<X>>);
STATIC_ASSERT(is_default_constructible_v<atomic<Y>>);
STATIC_ASSERT(!is_default_constructible_v<atomic<reference_wrapper<int>>>);
STATIC_ASSERT(!is_default_constructible_v<atomic<reference_wrapper<const int>>>);
STATIC_ASSERT(!is_default_constructible_v<atomic<reference_wrapper<int()>>>);


// Also test P0418R2 atomic compare_exchange memory_order Requirements
void test_compare_exchange_relaxed_memory_orders() {
Expand Down
Loading