2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.other / dyncast3.C
blobcd59efa6ca8b6f824de80273a49e14c4f8e16878
1 // { dg-do run  }
2 // Author: Alfred Miniarik <a8601248@unet.univie.ac.at>
3 // test of dynamic_cast
4 // runtime detecting of nonpublic
5 // inheritance within a cast
6 // and therefor failing with result 0.
8 extern "C" void abort();
9 extern "C" int printf (const char *, ...);
11 static int errors = 0;
13 void error(int i)
15   printf("Error %i\n",i);
16   errors++;
19 struct A {virtual ~A(){}};
20 struct B : private virtual A {};
21 struct C : virtual A {};
22 struct D : B, C {};
24 int 
25 main()
27   D d;
28   A* ap= &d;
29   if(&d != dynamic_cast<D*>(ap)) error(1);
30   if((B*)&d != dynamic_cast<B*>(ap)) error(2);
31   if((C*)&d != dynamic_cast<C*>(ap)) error(3);
32   return errors ? 1 : 0;