| 1 | // { dg-do run { target c++20 } } |
| 2 | // { dg-require-effective-target libatomic_available } |
| 3 | // { dg-additional-options "[atomic_link_flags [get_multilibs]] -latomic" } |
| 4 | |
| 5 | #include <atomic> |
| 6 | #include <cstring> |
| 7 | #include <testsuite_hooks.h> |
| 8 | |
| 9 | long double zld(10.5); |
| 10 | constexpr std::atomic<long double> cld(10.5); |
| 11 | std::atomic<long double> gld(10.5); |
| 12 | |
| 13 | template<typename T> |
| 14 | void test_floating(std::atomic<T>& g, const T& zp) |
| 15 | { |
| 16 | T const d = T(7.5); |
| 17 | T t; |
| 18 | |
| 19 | std::memcpy(&t, &zp, sizeof(T)); |
| 20 | VERIFY( g.compare_exchange_strong(t, d) ); |
| 21 | |
| 22 | static std::atomic<T> st(T(10.5)); |
| 23 | std::memcpy(&t, &zp, sizeof(T)); |
| 24 | VERIFY( st.compare_exchange_strong(t, d) ); |
| 25 | |
| 26 | thread_local std::atomic<T> tl(T(10.5)); |
| 27 | std::memcpy(&t, &zp, sizeof(T)); |
| 28 | VERIFY( tl.compare_exchange_strong(t, d) ); |
| 29 | |
| 30 | std::atomic<T> l(T(10.5)); |
| 31 | std::memcpy(&t, &zp, sizeof(T)); |
| 32 | VERIFY( l.compare_exchange_strong(t, d) ); |
| 33 | |
| 34 | std::atomic<T>* h = new std::atomic<T>(T(10.5)); |
| 35 | std::memcpy(&t, &zp, sizeof(T)); |
| 36 | VERIFY( h->compare_exchange_strong(t, d) ); |
| 37 | delete h; |
| 38 | |
| 39 | constexpr std::atomic<T> cl(T(10.5)); |
| 40 | } |
| 41 | |
| 42 | int main() |
| 43 | { |
| 44 | test_floating(gld, zld); |
| 45 | } |