1 /* { dg-do compile } */
2 /* { dg-options "-O3 -fno-ipa-cp -fdump-ipa-inline-details -fno-early-inlining" } */
3 struct A {
fooA4   virtual int foo () {return 1;}
wrapfooA5   void wrapfoo () {foo();}
AA6   A() {wrapfoo();}
7 };
new(__SIZE_TYPE__ s,void * buf)8 inline void* operator new(__SIZE_TYPE__ s, void* buf) throw() {
9    return buf;
10 }
fooB11 struct B:A {virtual int foo () {return 2;}};
12 
13 void dostuff(struct A *);
14 
15 static void
test2(struct A * a)16 test2 (struct A *a)
17 {
18   dostuff (a);
19   if (a->foo ()!= 2)
20     __builtin_abort ();
21 }
22 
23 static void
test(struct A * a)24 test (struct A *a)
25 {
26   dostuff (a);
27   static_cast<B*>(a)->~B();
28   new(a) B();
29   test2(a);
30 }
31 
main()32 int main()
33 {
34   struct B a;
35   dostuff (&a);
36   test (&a);
37 }
38 
39 /* One invocation is A::foo () other is B::foo () even though the type is destroyed and rebuilt in test() */
40 /* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*A::foo" 1 "inline"  } } */
41 /* { dg-final { scan-ipa-dump-times "Discovered a virtual call to a known target\[^\\n\]*B::foo" 1 "inline"  } } */
42