Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.other/dyncast3.C

raw
1 // { dg-do run }
2 // Author: Alfred Miniarik <[email protected]>
3 // test of dynamic_cast
4 // runtime detecting of nonpublic
5 // inheritance within a cast
6 // and therefor failing with result 0.
7
8 extern "C" void abort();
9 extern "C" int printf (const char *, ...);
10
11 static int errors = 0;
12
13 void error(int i)
14 {
15 printf("Error %i\n",i);
16 errors++;
17 }
18
19 struct A {virtual ~A(){}};
20 struct B : private virtual A {};
21 struct C : virtual A {};
22 struct D : B, C {};
23
24 int
25 main()
26 {
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;
33 }