Skip to content

Commit 0750a60

Browse files
Implement LWG-4169
1 parent 5e0ddad commit 0750a60

File tree

2 files changed

+13
-1
lines changed
  • stl/inc
  • tests/std/tests/Dev11_0863628_atomic_compare_exchange

2 files changed

+13
-1
lines changed

stl/inc/atomic

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,7 @@ public:
21232123

21242124
using _Base::_Base;
21252125

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

21282129
atomic(const atomic&) = delete;

tests/std/tests/Dev11_0863628_atomic_compare_exchange/test.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
#include <cstdint>
1313
#include <cstdlib>
1414
#include <cstring>
15+
#include <functional>
1516
#include <limits>
1617
#include <new>
1718
#include <type_traits>
1819

19-
2020
using namespace std;
2121

2222
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
@@ -438,6 +438,17 @@ STATIC_ASSERT(atomic<void*>::is_always_lock_free);
438438
STATIC_ASSERT(atomic<int (*)(int)>::is_always_lock_free);
439439
#endif // _HAS_CXX17
440440

441+
// Also test LWG-4169 std::atomic<T>'s default constructor should be constrained
442+
// (backported to C++14/17 modes as we backported P0883R2)
443+
STATIC_ASSERT(is_default_constructible_v<atomic<int>>);
444+
STATIC_ASSERT(is_default_constructible_v<atomic<bool>>);
445+
STATIC_ASSERT(is_default_constructible_v<atomic<void*>>);
446+
STATIC_ASSERT(is_default_constructible_v<atomic<X>>);
447+
STATIC_ASSERT(is_default_constructible_v<atomic<Y>>);
448+
STATIC_ASSERT(!is_default_constructible_v<atomic<reference_wrapper<int>>>);
449+
STATIC_ASSERT(!is_default_constructible_v<atomic<reference_wrapper<const int>>>);
450+
STATIC_ASSERT(!is_default_constructible_v<atomic<reference_wrapper<int()>>>);
451+
441452

442453
// Also test P0418R2 atomic compare_exchange memory_order Requirements
443454
void test_compare_exchange_relaxed_memory_orders() {

0 commit comments

Comments
 (0)