2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.mike / dyncast5.C
blobb6adac72ac2088018ad54e313f2251d497b9ab8b
1 // { dg-do run  }
2 #include <stddef.h>
4 void *p;
5 int fail;
7 class HeapTracked {
8 public:
9     virtual ~HeapTracked() = 0;
10     void *operator new(size_t size);
11     void operator delete(void *ptr);
12     static bool isObjectAllocation(const HeapTracked *ptr);
15 HeapTracked::~HeapTracked(){}
16 void * HeapTracked::operator new(size_t size)
18     void * memPtr = ::operator new(size);
19     p = memPtr;
20     return memPtr;
23 void HeapTracked::operator delete(void *ptr)
25     if (p != ptr)
26       fail = 1;
27     ::operator delete(ptr);
30 bool HeapTracked::isObjectAllocation(const HeapTracked *ptr)
32     if (p != const_cast<void*>(dynamic_cast<const void*>(ptr)))
33       fail = 1;
34     return false;
37 class Mumble1: public virtual HeapTracked {
38     double d;
39 public:
40     virtual ~Mumble1(){}
43 class Mumble2: public virtual HeapTracked {
44     double d;
45 public:
46     virtual ~Mumble2(){}
49 class Foo: virtual public HeapTracked,
50            virtual public Mumble1,
51            virtual public Mumble2 {
52 public:
53     ~Foo(){}
56 int main()
58     Foo *pf = new Foo;
59     pf->isObjectAllocation(pf);
61     Mumble1 *pm1 = pf;
62     pm1->isObjectAllocation(pm1);
64     Mumble2 *pm2 = pf;
65     pm2->isObjectAllocation(pm2);
67     // delete pf;
68     // delete pm1;
69     delete pm2;
71     return fail;