Debian Codegraph @

libcxx/test/std/utilities/memory/specialized.algorithms/specialized.addressof/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 // <memory>
10
11 // template <ObjectType T> T* addressof(T& r);
12
13 #include <memory>
14 #include <cassert>
15
16 #include "test_macros.h"
17
18 struct A
19 {
20 void operator&() const {}
21 };
22
23 struct nothing {
24 operator char&()
25 {
26 static char c;
27 return c;
28 }
29 };
30
31 int main(int, char**)
32 {
33 {
34 int i;
35 double d;
36 assert(std::addressof(i) == &i);
37 assert(std::addressof(d) == &d);
38 A* tp = new A;
39 const A* ctp = tp;
40 assert(std::addressof(*tp) == tp);
41 assert(std::addressof(*ctp) == tp);
42 delete tp;
43 }
44 {
45 union
46 {
47 nothing n;
48 int i;
49 };
50 assert(std::addressof(n) == (void*)std::addressof(i));
51 }
52
53 return 0;
54 }