1 // This testcase used to crash while looking in A for my_module. I'm still 2 // not sure it's well-formed, but it works now because of the optimization 3 // to look at the expected address first. 4 5 // { dg-do run } 6 7 extern "C" int puts (const char *); 8 extern "C" void abort (); 9 10 struct my_object 11 { my_objectmy_object12 my_object() { puts ("in my_object ctor");} ~my_objectmy_object13 virtual ~my_object() { puts ("in my_object dtor"); } 14 }; 15 16 my_object* my_module_ptr = 0; 17 18 struct my_module : my_object 19 { my_modulemy_module20 my_module() 21 { 22 puts ("in my_module ctor, setting up ptr"); 23 my_module_ptr = this; 24 } ~my_modulemy_module25 ~my_module() { puts ("in my_module dtor");} 26 }; 27 28 struct D 29 { DD30 D() { puts ("in D ctor"); } 31 virtual ~D(); 32 }; 33 ~D()34D::~D() 35 { 36 puts ("in D dtor"); 37 puts ("before DCASTing to my_module*"); 38 my_module* m = dynamic_cast<my_module*>(my_module_ptr); 39 if (m != my_module_ptr) 40 abort (); 41 puts ("after DCASTing to my_module*"); 42 } 43 44 struct my_interface 45 { my_interfacemy_interface46 my_interface() { puts ("in my_interface ctor");} ~my_interfacemy_interface47 ~my_interface() { puts ("in my_interface dtor");} 48 }; 49 50 struct myif : virtual my_interface 51 { myifmyif52 myif() { puts ("in myif ctor");} ~myifmyif53 ~myif() { puts ("in myif dtor");} 54 }; 55 56 struct A: virtual myif 57 { AA58 A() { puts ("in A ctor"); } ~AA59 ~A() { puts ("in A dtor"); } 60 61 D d; 62 }; 63 64 struct B: virtual myif 65 { BB66 B() { puts ("in B ctor"); } ~BB67 ~B() { puts ("in B dtor"); } 68 69 D d; 70 }; 71 72 struct C : my_module, A, B 73 { CC74 C() { puts ("in C ctor");} ~CC75 ~C() { puts ("in C dtor"); } 76 }; 77 main(int,char **)78int main(int, char**) 79 { 80 C t; 81 } 82