summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/29_atomics/atomic_ref/address.cc
blob: 42a080af55e296c2d28d7ba191b2d6c72a78be4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// { dg-do run { target c++26 } }
// { dg-require-atomic-cmpxchg-word "" }
// { dg-add-options libatomic }

#include <atomic>
#include <memory>
#include <type_traits>

#include <testsuite_hooks.h>

template <typename T>
void testAtomicRefAddress()
{
  T x(T(42));
  const std::atomic_ref<T> a(x);

  static_assert( noexcept(a.address()) );
  static_assert( std::is_same_v<decltype(a.address()), T*> );
  VERIFY( std::addressof(x) == a.address() );
}

template <typename T>
void testAtomicRefAddressForCV()
{
  testAtomicRefAddress<T>();
  testAtomicRefAddress<const T>();
  testAtomicRefAddress<volatile T>();
  testAtomicRefAddress<const volatile T>();
}

int
main ()
{
  struct X { int c; };
  testAtomicRefAddressForCV<X>();
  testAtomicRefAddressForCV<int>();
  testAtomicRefAddressForCV<float>();
  testAtomicRefAddressForCV<char*>();
}