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. 7 8extern "C" void abort(); 9extern "C" int printf (const char *, ...); 10 11static int errors = 0; 12 13void error(int i) 14{ 15 printf("Error %i\n",i); 16 errors++; 17} 18 19struct A {virtual ~A(){}}; 20struct B : private virtual A {}; 21struct C : virtual A {}; 22struct D : B, C {}; 23 24int 25main() 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} 34