From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; 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. --- gcc/testsuite/g++.old-deja/g++.other/dyncast2.C | 85 +++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 gcc/testsuite/g++.old-deja/g++.other/dyncast2.C (limited to 'gcc/testsuite/g++.old-deja/g++.other/dyncast2.C') diff --git a/gcc/testsuite/g++.old-deja/g++.other/dyncast2.C b/gcc/testsuite/g++.old-deja/g++.other/dyncast2.C new file mode 100644 index 000000000..bea82cb46 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.other/dyncast2.C @@ -0,0 +1,85 @@ +// { dg-do run } +// Author: Alfred Miniarik +// test of dynamic_cast +// runtime detecting of valid +// downcasts within nonpublic +// baseclasses. + +extern "C" void abort(); +extern "C" int printf (const char *, ...); + +static int errors = 0; + +void error(int i) +{ + printf("Error %i\n",i); + errors++; +} + +// 1. downcast +// 1.1 single inheritance case + +struct A {virtual ~A(){} int i;}; +struct B : A {int i;}; +struct C : B {int i;}; +struct CC : C {}; +class D : C {int i;}; + +struct E : D {int i;}; +class F : E {int i;}; + +void +test01 () +{ + D d; + if((C*)&d != dynamic_cast ((A*)&d)) error(1); + if((C*)&d != dynamic_cast ((B*)&d)) error(2); + if((B*)&d != dynamic_cast ((A*)&d)) error(3); + + E e; + if((C*)&e != dynamic_cast ((A*)&e)) error(4); + + F f; + if((C*)&f != dynamic_cast ((B*)&f)) error(5); + if((B*)&f != dynamic_cast ((A*)&f)) error(6); + if((E*)&f != dynamic_cast ((D*)&f)) error(7); + if(dynamic_cast ((C*)&f)) error(8); //counter example +} + +// 1.2 multiple inheritance case + +struct G : CC, F{}; + +void +test02 () +{ + G g; + if((B*)(F*)&g != dynamic_cast ((A*)(F*)&g)) error(9); + if(dynamic_cast ((A*)(F*)&g)) error(10); + if(dynamic_cast ((B*)(F*)&g)) error(11); +} + +// 2. crosscast (always fail) + +struct I : C{}; +struct J : F{}; +struct K : I, J{}; +class L : K{}; + +void +test03 () +{ + L l; + if(dynamic_cast ((I*)&l)) error(12); + if(dynamic_cast ((E*)&l)) error(13); + if(dynamic_cast ((J*)&l)) error(14); +} + +int +main () +{ + test01(); + test02(); + test03(); + return errors ? 1 : 0; +} -- cgit v1.2.3