| 1 |
// { dg-do compile { target c++11 } } |
| 2 |
|
| 3 |
#include <atomic> |
| 4 |
#include <type_traits> |
| 5 |
|
| 6 |
// C++20 / P0883R2 makes std::atomic value-initialize, so it's no |
| 7 |
// longer going to be trivially default constructible; check that it |
| 8 |
// still is in earlier language modes. |
| 9 |
// (We are not applying that paper as a DR.) |
| 10 |
#if __cpp_lib_atomic_value_initialization |
| 11 |
constexpr bool atomic_default_ctor_is_trivial = false; |
| 12 |
#else |
| 13 |
constexpr bool atomic_default_ctor_is_trivial = true; |
| 14 |
#endif |
| 15 |
|
| 16 |
template<typename T> |
| 17 |
using isTDC = std::is_trivially_default_constructible<T>; |
| 18 |
|
| 19 |
static_assert(isTDC<std::atomic<bool>>::value == atomic_default_ctor_is_trivial); |
| 20 |
static_assert(isTDC<std::atomic<char>>::value == atomic_default_ctor_is_trivial); |
| 21 |
static_assert(isTDC<std::atomic<unsigned char>>::value == atomic_default_ctor_is_trivial); |
| 22 |
static_assert(isTDC<std::atomic<int>>::value == atomic_default_ctor_is_trivial); |
| 23 |
static_assert(isTDC<std::atomic<long>>::value == atomic_default_ctor_is_trivial); |
| 24 |
static_assert(isTDC<std::atomic<unsigned long long>>::value == atomic_default_ctor_is_trivial); |
| 25 |
static_assert(isTDC<std::atomic<int*>>::value == atomic_default_ctor_is_trivial); |
| 26 |
|
| 27 |
struct DefaultConstructible |
| 28 |
{ |
| 29 |
int a; |
| 30 |
long long b; |
| 31 |
char* p; |
| 32 |
}; |
| 33 |
static_assert(isTDC<std::atomic<DefaultConstructible>>::value == atomic_default_ctor_is_trivial); |
| 34 |
|
| 35 |
struct NonDefaultConstructible |
| 36 |
{ |
| 37 |
NonDefaultConstructible(int i) : val(i) { } |
| 38 |
int val; |
| 39 |
}; |
| 40 |
// Not default constructible, therefore not trivially default constructible |
| 41 |
static_assert(isTDC<std::atomic<NonDefaultConstructible>>::value == false); |