1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11, c++14
10
11// <memory>
12
13// template <ObjectType T> constexpr T* addressof(T& r);
14
15#include <memory>
16#include <cassert>
17
18#include "test_macros.h"
19
20struct Pointer {
21 constexpr Pointer(void* v) : value(v) {}
22 void* value;
23};
24
25struct A
26{
27 constexpr A() : n(42) {}
28 void operator&() const { }
29 int n;
30};
31
32constexpr int i = 0;
33constexpr double d = 0.0;
34constexpr A a{};
35
36int main(int, char**)
37{
38 static_assert(std::addressof(r: i) == &i, "");
39 static_assert(std::addressof(r: d) == &d, "");
40 constexpr const A* ap = std::addressof(r: a);
41 static_assert(&ap->n == &a.n, "");
42
43 return 0;
44}
45

source code of libcxx/test/std/utilities/memory/specialized.algorithms/specialized.addressof/constexpr_addressof.pass.cpp