1 // { dg-do run { target c++11 } } 2 // { dg-additional-options "-O2" } 3 4 void * 5 operator new (decltype (sizeof (0)), void *p) 6 { 7 return p; 8 } 9 10 namespace std 11 { 12 template <typename T> 13 T * launder(T * p)14 launder (T *p) 15 { 16 return __builtin_launder (p); 17 } 18 } 19 20 struct A 21 { 22 virtual int f (); 23 }; 24 25 struct B : A 26 { fB27 virtual int f () 28 { 29 new (this) A; 30 return 1; 31 } 32 }; 33 34 int f()35A::f () 36 { 37 new (this) B; 38 return 2; 39 } 40 41 static_assert (sizeof (B) == sizeof (A), ""); 42 43 int main()44main () 45 { 46 A a; 47 int n = a.f (); 48 int m = std::launder (&a)->f (); 49 if (n != 2 || m != 1) 50 __builtin_abort (); 51 } 52