summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/ipa/devirt-6.C
blob: e9a5d7093b9f40858b2a9d000fbd007eab5712f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Verify that we either do not do any devirtualization or correctly
   spot that foo changes the dynamic type of the passed object.  */

/* { dg-do run } */
/* { dg-options "-O3"  } */

extern "C" void abort (void);
extern "C" void *malloc(__SIZE_TYPE__);

inline void* operator new(__SIZE_TYPE__, void* __p) throw() { return __p;}

int x;

class A {
public:
   virtual ~A() { }
};

class B : public A {
public:
   virtual ~B() { if (x == 1) abort (); x = 1; }
};

void __attribute__((noinline,noclone)) foo (void *p)
{
 B *b = reinterpret_cast<B *>(p);
 b->~B();
 new (p) A;
}

int main()
{
 void *p = __builtin_malloc (sizeof (B));
 new (p) B;
 foo(p);
 reinterpret_cast<A *>(p)->~A();
 return 0;
}