aboutsummaryrefslogtreecommitdiff
path: root/libcxx/test/std/atomics/atomics.ref/address.pass.cpp
blob: e0db6a93e2eda415101681dc0a6e243f5e65352a (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
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// REQUIRES: std-at-least-c++26

// constexpr T* address() const noexcept;

#include <atomic>
#include <cassert>
#include <concepts>
#include <memory>

#include "atomic_helpers.h"
#include "test_macros.h"

template <typename T>
struct TestAddress {
  void operator()() const {
    T x(T(1));
    const std::atomic_ref<T> a(x);

    std::same_as<T*> decltype(auto) p = a.address();
    assert(std::addressof(x) == p);

    static_assert(noexcept((a.address())));
  }
};

int main(int, char**) {
  TestEachAtomicType<TestAddress>()();

  return 0;
}