| 1 |
// { dg-do run { target c++11 } } |
| 2 |
// { dg-additional-options "-O2" } |
| 3 |
// { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } } |
| 4 |
|
| 5 |
#include <cassert> |
| 6 |
|
| 7 |
void * |
| 8 |
operator new (decltype (sizeof (0)), void *p) |
| 9 |
{ |
| 10 |
return p; |
| 11 |
} |
| 12 |
|
| 13 |
namespace std |
| 14 |
{ |
| 15 |
template <typename T> |
| 16 |
T * |
| 17 |
launder (T *p) |
| 18 |
{ |
| 19 |
return __builtin_launder (p); |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
struct A |
| 24 |
{ |
| 25 |
int& x; |
| 26 |
}; |
| 27 |
|
| 28 |
struct B |
| 29 |
{ |
| 30 |
A a; |
| 31 |
}; |
| 32 |
|
| 33 |
int |
| 34 |
main () |
| 35 |
{ |
| 36 |
int x = 42; |
| 37 |
B b{{x}}; |
| 38 |
int y = 666; |
| 39 |
new (&b.a) A{y}; |
| 40 |
assert(std::launder(&b.a)->x == 666); |
| 41 |
} |