| 1 | // { dg-do compile { target c++23 } } |
| 2 | // { dg-add-options no_pch } |
| 3 | |
| 4 | #include <stdatomic.h> |
| 5 | |
| 6 | #ifndef __cpp_lib_stdatomic_h |
| 7 | # error "Feature test macro for stdatomic.h is missing in <stdatomic.h>" |
| 8 | #elif __cpp_lib_stdatomic_h != 202011L |
| 9 | # error "Feature test macro for stdatomic.h has wrong value in <stdatomic.h>" |
| 10 | #endif |
| 11 | |
| 12 | #ifndef ATOMIC_BOOL_LOCK_FREE |
| 13 | #error ATOMIC_BOOL_LOCK_FREE is not defined in <stdatomic.h> |
| 14 | #endif |
| 15 | #ifndef ATOMIC_CHAR_LOCK_FREE |
| 16 | #error ATOMIC_CHAR_LOCK_FREE is not defined in <stdatomic.h> |
| 17 | #endif |
| 18 | #ifndef ATOMIC_CHAR16_T_LOCK_FREE |
| 19 | #error ATOMIC_CHAR16_T_LOCK_FREE is not defined in <stdatomic.h> |
| 20 | #endif |
| 21 | #ifndef ATOMIC_CHAR32_T_LOCK_FREE |
| 22 | #error ATOMIC_CHAR32_T_LOCK_FREE is not defined in <stdatomic.h> |
| 23 | #endif |
| 24 | #ifndef ATOMIC_WCHAR_T_LOCK_FREE |
| 25 | #error ATOMIC_WCHAR_T_LOCK_FREE is not defined in <stdatomic.h> |
| 26 | #endif |
| 27 | #ifndef ATOMIC_SHORT_LOCK_FREE |
| 28 | #error ATOMIC_SHORT_LOCK_FREE is not defined in <stdatomic.h> |
| 29 | #endif |
| 30 | #ifndef ATOMIC_INT_LOCK_FREE |
| 31 | #error ATOMIC_INT_LOCK_FREE is not defined in <stdatomic.h> |
| 32 | #endif |
| 33 | #ifndef ATOMIC_LONG_LOCK_FREE |
| 34 | #error ATOMIC_LONG_LOCK_FREE is not defined in <stdatomic.h> |
| 35 | #endif |
| 36 | #ifndef ATOMIC_LLONG_LOCK_FREE |
| 37 | #error ATOMIC_LLONG_LOCK_FREE is not defined in <stdatomic.h> |
| 38 | #endif |
| 39 | #ifndef ATOMIC_POINTER_LOCK_FREE |
| 40 | #error ATOMIC_POINTER_LOCK_FREE is not defined in <stdatomic.h> |
| 41 | #endif |
| 42 | |
| 43 | constexpr const memory_order* orders[] = { |
| 44 | &memory_order_relaxed, &memory_order_consume, &memory_order_acquire, |
| 45 | &memory_order_release, &memory_order_acq_rel, &memory_order_seq_cst |
| 46 | }; |
| 47 | |
| 48 | constexpr atomic_flag flag{}; |
| 49 | |
| 50 | template<typename A, typename B> constexpr bool is_same = false; |
| 51 | template<typename A> constexpr bool is_same<A, A> = true; |
| 52 | |
| 53 | static_assert(is_same<atomic_bool, _Atomic(bool)>); |
| 54 | static_assert(is_same<atomic_char, _Atomic(char)>); |
| 55 | static_assert(is_same<atomic_schar, _Atomic(signed char)>); |
| 56 | static_assert(is_same<atomic_uchar, _Atomic(unsigned char)>); |
| 57 | static_assert(is_same<atomic_short, _Atomic(short)>); |
| 58 | static_assert(is_same<atomic_ushort, _Atomic(unsigned short)>); |
| 59 | static_assert(is_same<atomic_int, _Atomic(int)>); |
| 60 | static_assert(is_same<atomic_uint, _Atomic(unsigned int)>); |
| 61 | static_assert(is_same<atomic_long, _Atomic(long)>); |
| 62 | static_assert(is_same<atomic_ulong, _Atomic(unsigned long)>); |
| 63 | static_assert(is_same<atomic_llong, _Atomic(long long)>); |
| 64 | static_assert(is_same<atomic_ullong, _Atomic(unsigned long long)>); |
| 65 | #ifdef _GLIBCXX_USE_CHAR8_T |
| 66 | static_assert(is_same<atomic_char8_t, _Atomic(char8_t)>); |
| 67 | #endif |
| 68 | static_assert(is_same<atomic_char16_t, _Atomic(char16_t)>); |
| 69 | static_assert(is_same<atomic_char32_t, _Atomic(char32_t)>); |
| 70 | static_assert(is_same<atomic_wchar_t, _Atomic(wchar_t)>); |
| 71 | |
| 72 | #include <stdint.h> |
| 73 | #ifdef _GLIBCXX_USE_C99_STDINT |
| 74 | static_assert(is_same<atomic_int8_t, _Atomic(int8_t)>); |
| 75 | static_assert(is_same<atomic_uint8_t, _Atomic(uint8_t)>); |
| 76 | static_assert(is_same<atomic_int16_t, _Atomic(int16_t)>); |
| 77 | static_assert(is_same<atomic_uint16_t, _Atomic(uint16_t)>); |
| 78 | static_assert(is_same<atomic_int32_t, _Atomic(int32_t)>); |
| 79 | static_assert(is_same<atomic_uint32_t, _Atomic(uint32_t)>); |
| 80 | static_assert(is_same<atomic_int64_t, _Atomic(int64_t)>); |
| 81 | static_assert(is_same<atomic_uint64_t, _Atomic(uint64_t)>); |
| 82 | #endif |
| 83 | static_assert(is_same<atomic_int_least8_t, _Atomic(int_least8_t)>); |
| 84 | static_assert(is_same<atomic_uint_least8_t, _Atomic(uint_least8_t)>); |
| 85 | static_assert(is_same<atomic_int_least16_t, _Atomic(int_least16_t)>); |
| 86 | static_assert(is_same<atomic_uint_least16_t, _Atomic(uint_least16_t)>); |
| 87 | static_assert(is_same<atomic_int_least32_t, _Atomic(int_least32_t)>); |
| 88 | static_assert(is_same<atomic_uint_least32_t, _Atomic(uint_least32_t)>); |
| 89 | static_assert(is_same<atomic_int_least64_t, _Atomic(int_least64_t)>); |
| 90 | static_assert(is_same<atomic_uint_least64_t, _Atomic(uint_least64_t)>); |
| 91 | static_assert(is_same<atomic_int_fast8_t, _Atomic(int_fast8_t)>); |
| 92 | static_assert(is_same<atomic_uint_fast8_t, _Atomic(uint_fast8_t)>); |
| 93 | static_assert(is_same<atomic_int_fast16_t, _Atomic(int_fast16_t)>); |
| 94 | static_assert(is_same<atomic_uint_fast16_t, _Atomic(uint_fast16_t)>); |
| 95 | static_assert(is_same<atomic_int_fast32_t, _Atomic(int_fast32_t)>); |
| 96 | static_assert(is_same<atomic_uint_fast32_t, _Atomic(uint_fast32_t)>); |
| 97 | static_assert(is_same<atomic_int_fast64_t, _Atomic(int_fast64_t)>); |
| 98 | static_assert(is_same<atomic_uint_fast64_t, _Atomic(uint_fast64_t)>); |
| 99 | static_assert(is_same<atomic_intptr_t, _Atomic(intptr_t)>); |
| 100 | static_assert(is_same<atomic_uintptr_t, _Atomic(uintptr_t)>); |
| 101 | static_assert(is_same<atomic_intmax_t, _Atomic(intmax_t)>); |
| 102 | static_assert(is_same<atomic_uintmax_t, _Atomic(uintmax_t)>); |
| 103 | #include <stddef.h> |
| 104 | static_assert(is_same<atomic_size_t, _Atomic(size_t)>); |
| 105 | static_assert(is_same<atomic_ptrdiff_t, _Atomic(ptrdiff_t)>); |
| 106 | |
| 107 | static_assert( requires (::atomic_int* i, int* e) { |
| 108 | ::atomic_is_lock_free(i); |
| 109 | ::atomic_load(i); |
| 110 | ::atomic_load_explicit(i, memory_order_relaxed); |
| 111 | ::atomic_store(i, 2); |
| 112 | ::atomic_store_explicit(i, 3, memory_order_release); |
| 113 | ::atomic_exchange(i, 2); |
| 114 | ::atomic_exchange_explicit(i, 3, memory_order_acq_rel); |
| 115 | ::atomic_compare_exchange_strong(i, e, 2); |
| 116 | ::atomic_compare_exchange_strong_explicit(i, e, 3, |
| 117 | memory_order_acq_rel, |
| 118 | memory_order_relaxed); |
| 119 | ::atomic_compare_exchange_weak(i, e, 2); |
| 120 | ::atomic_compare_exchange_weak_explicit(i, e, 3, |
| 121 | memory_order_acq_rel, |
| 122 | memory_order_relaxed); |
| 123 | |
| 124 | ::atomic_fetch_add(i, 1); |
| 125 | ::atomic_fetch_add_explicit(i, 1, memory_order_relaxed); |
| 126 | ::atomic_fetch_sub(i, 1); |
| 127 | ::atomic_fetch_sub_explicit(i, 1, memory_order_relaxed); |
| 128 | ::atomic_fetch_and(i, 1); |
| 129 | ::atomic_fetch_and_explicit(i, 1, memory_order_relaxed); |
| 130 | ::atomic_fetch_or(i, 1); |
| 131 | ::atomic_fetch_or_explicit(i, 1, memory_order_relaxed); |
| 132 | ::atomic_fetch_xor(i, 1); |
| 133 | ::atomic_fetch_xor_explicit(i, 1, memory_order_relaxed); |
| 134 | } ); |
| 135 | |
| 136 | static_assert( requires (::atomic_flag* f) { |
| 137 | ::atomic_flag_test_and_set(f); |
| 138 | ::atomic_flag_test_and_set_explicit(f, memory_order_relaxed); |
| 139 | ::atomic_flag_clear(f); |
| 140 | ::atomic_flag_clear_explicit(f, memory_order_acq_rel); |
| 141 | } ); |
| 142 | |
| 143 | static_assert( requires (::memory_order o) { |
| 144 | ::atomic_thread_fence(o); |
| 145 | ::atomic_signal_fence(o); |
| 146 | } ); |