Merge from trunk
[official-gcc.git] / gcc / testsuite / g++.dg / ipa / devirt-6.C
blobe9a5d7093b9f40858b2a9d000fbd007eab5712f6
1 /* Verify that we either do not do any devirtualization or correctly
2    spot that foo changes the dynamic type of the passed object.  */
4 /* { dg-do run } */
5 /* { dg-options "-O3"  } */
7 extern "C" void abort (void);
8 extern "C" void *malloc(__SIZE_TYPE__);
10 inline void* operator new(__SIZE_TYPE__, void* __p) throw() { return __p;}
12 int x;
14 class A {
15 public:
16    virtual ~A() { }
19 class B : public A {
20 public:
21    virtual ~B() { if (x == 1) abort (); x = 1; }
24 void __attribute__((noinline,noclone)) foo (void *p)
26  B *b = reinterpret_cast<B *>(p);
27  b->~B();
28  new (p) A;
31 int main()
33  void *p = __builtin_malloc (sizeof (B));
34  new (p) B;
35  foo(p);
36  reinterpret_cast<A *>(p)->~A();
37  return 0;