Debian Codegraph @

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

raw
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
20 struct Pointer {
21 constexpr Pointer(void* v) : value(v) {}
22 void* value;
23 };
24
25 struct A
26 {
27 constexpr A() : n(42) {}
28 void operator&() const { }
29 int n;
30 };
31
32 constexpr int i = 0;
33 constexpr double d = 0.0;
34 constexpr A a{};
35
36 int main(int, char**)
37 {
38 static_assert(std::addressof(i) == &i, "");
39 static_assert(std::addressof(d) == &d, "");
40 constexpr const A* ap = std::addressof(a);
41 static_assert(&ap->n == &a.n, "");
42
43 return 0;
44 }