libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

constexpr_addressof.pass.cpp (967B)


      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 // UNSUPPORTED: c++98, c++03, c++11, c++14
     11 // XFAIL: gcc-4, gcc-5, gcc-6
     12 
     13 // <memory>
     14 
     15 // template <ObjectType T> constexpr T* addressof(T& r);
     16 
     17 #include <memory>
     18 #include <cassert>
     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()
     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 }