1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <memory> 11 12 // template <ObjectType T> T* addressof(T& r); 13 14 #include <memory> 15 #include <cassert> 16 17 struct A 18 { operator &A19 void operator&() const {} 20 }; 21 22 struct nothing { operator char¬hing23 operator char&() 24 { 25 static char c; 26 return c; 27 } 28 }; 29 main()30int main() 31 { 32 { 33 int i; 34 double d; 35 assert(std::addressof(i) == &i); 36 assert(std::addressof(d) == &d); 37 A* tp = new A; 38 const A* ctp = tp; 39 assert(std::addressof(*tp) == tp); 40 assert(std::addressof(*ctp) == tp); 41 delete tp; 42 } 43 { 44 union 45 { 46 nothing n; 47 int i; 48 }; 49 assert(std::addressof(n) == (void*)std::addressof(i)); 50 } 51 } 52