summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/rtti/dyncast3.C
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/g++.dg/rtti/dyncast3.C
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/g++.dg/rtti/dyncast3.C')
-rw-r--r--gcc/testsuite/g++.dg/rtti/dyncast3.C81
1 files changed, 81 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/rtti/dyncast3.C b/gcc/testsuite/g++.dg/rtti/dyncast3.C
new file mode 100644
index 000000000..08352599b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/rtti/dyncast3.C
@@ -0,0 +1,81 @@
+// This testcase used to crash while looking in A for my_module. I'm still
+// not sure it's well-formed, but it works now because of the optimization
+// to look at the expected address first.
+
+// { dg-do run }
+
+extern "C" int puts (const char *);
+extern "C" void abort ();
+
+struct my_object
+{
+ my_object() { puts ("in my_object ctor");}
+ virtual ~my_object() { puts ("in my_object dtor"); }
+};
+
+my_object* my_module_ptr = 0;
+
+struct my_module : my_object
+{
+ my_module()
+ {
+ puts ("in my_module ctor, setting up ptr");
+ my_module_ptr = this;
+ }
+ ~my_module() { puts ("in my_module dtor");}
+};
+
+struct D
+{
+ D() { puts ("in D ctor"); }
+ virtual ~D();
+};
+
+D::~D()
+{
+ puts ("in D dtor");
+ puts ("before DCASTing to my_module*");
+ my_module* m = dynamic_cast<my_module*>(my_module_ptr);
+ if (m != my_module_ptr)
+ abort ();
+ puts ("after DCASTing to my_module*");
+}
+
+struct my_interface
+{
+ my_interface() { puts ("in my_interface ctor");}
+ ~my_interface() { puts ("in my_interface dtor");}
+};
+
+struct myif : virtual my_interface
+{
+ myif() { puts ("in myif ctor");}
+ ~myif() { puts ("in myif dtor");}
+};
+
+struct A: virtual myif
+{
+ A() { puts ("in A ctor"); }
+ ~A() { puts ("in A dtor"); }
+
+ D d;
+};
+
+struct B: virtual myif
+{
+ B() { puts ("in B ctor"); }
+ ~B() { puts ("in B dtor"); }
+
+ D d;
+};
+
+struct C : my_module, A, B
+{
+ C() { puts ("in C ctor");}
+ ~C() { puts ("in C dtor"); }
+};
+
+int main(int, char**)
+{
+ C t;
+}