addressof.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
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
17struct A
18{
19    void operator&() const {}
20};
21
22int main()
23{
24    int i;
25    double d;
26    assert(std::addressof(i) == &i);
27    assert(std::addressof(d) == &d);
28    A* tp = new A;
29    const A* ctp = tp;
30    assert(std::addressof(*tp) == tp);
31    assert(std::addressof(*ctp) == tp);
32    delete tp;
33}
34