1 // LWG2296 - addressof should be constexpr
2 // { dg-do run { target c++11 } }
6 addressof (T &x) noexcept
8 return __builtin_addressof (x);
12 static_assert (__builtin_addressof (i) == &i, "");
13 static_assert (addressof (i) == &i, "");
16 static_assert (__builtin_addressof (j) == &i, "");
17 static_assert (addressof (j) == &i, "");
19 struct S { int s; } s;
20 static_assert (__builtin_addressof (s) == &s, "");
21 static_assert (addressof (s) == &s, "");
26 constexpr T () : p (addressof (tt)) {}
27 constexpr T *operator & () const { return p; }
32 static_assert (&t == __builtin_addressof (T::tt), "");
33 static_assert (&t == addressof (T::tt), "");
40 return __builtin_addressof (b ? x : y);
44 bar (bool b, S &c, S &d)
46 return __builtin_addressof (b ? c : d);
49 static_assert (foo (false) == &y, "");
50 static_assert (foo (true) == &x, "");
51 static_assert (bar (false, y, x) == &x, "");
52 static_assert (bar (true, y, x) == &y, "");
57 return addressof (b ? x : y);
61 bar2 (bool b, S &c, S &d)
63 return addressof (b ? c : d);
66 static_assert (foo2 (false) == &y, "");
67 static_assert (foo2 (true) == &x, "");
68 static_assert (bar2 (false, y, x) == &x, "");
69 static_assert (bar2 (true, y, x) == &y, "");
72 static_assert (__builtin_addressof (a) == &a, "");
73 static_assert (addressof (a) == &a, "");
74 constexpr int c[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
84 if (__builtin_addressof (T::tt) == __builtin_addressof (t)
85 || addressof (T::tt) == addressof (t)
87 || __builtin_addressof (baz) != baz
88 || addressof (baz) != baz)
91 // reinterpret casts are not constexprs
92 if (! (((int *) __builtin_addressof (s) == &s.s)
93 && ((int *) addressof (s) == &s.s)
94 && (__builtin_addressof (t) == (const T *) &t.p)
95 && (addressof (t) == (const T *) &t.p)
96 && ((const int *) __builtin_addressof (c) == &c[0])
97 && ((const int *) addressof (c) == &c[0])))