diff options
Diffstat (limited to 'gcc/testsuite/g++.old-deja/g++.eh')
72 files changed, 4128 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.old-deja/g++.eh/badalloc1.C b/gcc/testsuite/g++.old-deja/g++.eh/badalloc1.C new file mode 100644 index 000000000..cd902fbc3 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/badalloc1.C @@ -0,0 +1,133 @@ +// This fails for VxWorks RTPs because the initialization of +// __cxa_allocate_exception's emergency buffer mutex will +// itself call malloc(), and will fail if there is no more +// memory available. +// { dg-do run { xfail { { xstormy16-*-* *-*-darwin[3-7]* } || vxworks_rtp } } } +// Copyright (C) 2000, 2002, 2003, 2010 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 6 June 2000 <nathan@codesourcery.com> + +// Check we can throw a bad_alloc exception when malloc dies. + +typedef __SIZE_TYPE__ size_t; +extern "C" void abort(); +extern "C" void *memcpy(void *, const void *, size_t); + +// Assume that STACK_SIZE defined implies a system that does not have a +// large data space either, and additionally that we're not linking against +// a shared libstdc++ (which requires quite a bit more initialization space). +#ifdef STACK_SIZE +const int arena_size = 256; +#else +#if defined(__FreeBSD__) || defined(__sun__) || defined(__hpux__) || defined(__osf__) +// FreeBSD, Solaris, HP-UX and Tru64 UNIX with threads require even more +// space at initialization time. FreeBSD 5 now requires over 131072 bytes. +const int arena_size = 262144; +#else +const int arena_size = 32768; +#endif +#endif + +struct object +{ + size_t size __attribute__((aligned)); +}; + +static char arena[arena_size] __attribute__((aligned)); +static size_t pos; + +// So we can force a failure when needed. +static int fail; + +extern "C" void *malloc (size_t size) +{ + object *p = reinterpret_cast<object *>(&arena[pos]); + + if (fail) + return 0; + + p->size = size; + size = (size + __alignof__(object) - 1) & - __alignof__(object); + pos += size + sizeof(object); + + // Verify that we didn't run out of memory before getting initialized. + if (pos > arena_size) + abort (); + + return p + 1; +} + +extern "C" void free (void *) +{ +} + +extern "C" void *realloc (void *p, size_t size) +{ + void *r; + + if (p) + { + object *o = reinterpret_cast<object *>(p) - 1; + size_t old_size = o->size; + + if (old_size >= size) + { + r = p; + o->size = size; + } + else + { + r = malloc (size); + memcpy (r, p, old_size); + free (p); + } + } + else + r = malloc (size); + + return r; +} + +void fn_throw() throw(int) +{ + throw 1; +} + +void fn_rethrow() throw(int) +{ + try{fn_throw();} + catch(int a){ + throw;} +} + +void fn_catchthrow() throw(int) +{ + try{fn_throw();} + catch(int a){ + throw a + 1;} +} + +int main() +{ + /* On some systems (including FreeBSD and Solaris 2.10), + __cxa_get_globals will try to call "malloc" when threads are in + use. Therefore, we throw one exception up front so that + __cxa_get_globals is all set up. Ideally, this would not be + necessary, but it is a well-known idiom, and using this technique + means that we can still validate the fact that exceptions can be + thrown when malloc fails. */ + try{fn_throw();} + catch(int a){} + + fail = 1; + + try{fn_throw();} + catch(int a){} + + try{fn_rethrow();} + catch(int a){} + + try{fn_catchthrow();} + catch(int a){} + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch1.C b/gcc/testsuite/g++.old-deja/g++.eh/catch1.C new file mode 100644 index 000000000..7aa70ac97 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch1.C @@ -0,0 +1,18 @@ +// { dg-do assemble } +// +// Copyright (C) 1999 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 6 Jun 1999 <nathan@acm.org> + +// We cannot catch an incomplete type, or ptr to one + +struct A; // { dg-error "" } forward decl + +void fn() +{ + try {} + catch (A *p) {} // { dg-error "" } undefined type + try {} + catch (A p) {} // { dg-error "" } undefined type + try {} + catch (void const *p) {} // ok +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch10.C b/gcc/testsuite/g++.old-deja/g++.eh/catch10.C new file mode 100644 index 000000000..2300a9461 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch10.C @@ -0,0 +1,22 @@ +// { dg-do assemble } +// Test that we notice unfortunate handler ordering. + +struct A { }; +struct B: public A { }; +struct C: private A { }; + +void f(); +void g() +{ + try { f(); } + catch (...) { } // { dg-error "" } ... followed by others + catch (A*) { } + + try { f(); } + catch (A*) { } // { dg-warning "" } A* before B* + catch (B*) { } // { dg-warning "" } A* before B* + + try { f(); } + catch (A*) { } + catch (C*) { } // no warning; A is private base +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch11.C b/gcc/testsuite/g++.old-deja/g++.eh/catch11.C new file mode 100644 index 000000000..275a96ac7 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch11.C @@ -0,0 +1,64 @@ +// { dg-do run } +// Copyright (C) 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 24 May 2000 <nathan@codesourcery.com> + +// we should be able to catch a base a virtual, provided it is accessible by at +// least one public path +// -- public, << private, == virtual +// E<<B==A +// +--C==A +// +<<D==A + +struct A {}; +struct B : virtual A {}; +struct C : virtual A {}; +struct D : virtual A {}; +struct E : private B, public C, private D {}; + +extern "C" void abort (); + +void fne (E *e) +{ + throw e; +} + +void check(E *e) +{ + int caught; + + caught = 0; + try { fne(e); } + catch(A *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fne(e); } + catch(B *p) { abort ();} + catch(...) { caught = 1; } + if (!caught) abort(); + + caught = 0; + try { fne(e); } + catch(C *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fne(e); } + catch(D *p) { abort ();} + catch(...) { caught = 1; } + if (!caught) abort(); + + return; +} + +int main () +{ + E e; + + check (&e); + check ((E *)0); + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch12.C b/gcc/testsuite/g++.old-deja/g++.eh/catch12.C new file mode 100644 index 000000000..ae3b47cec --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch12.C @@ -0,0 +1,64 @@ +// { dg-do run } +// Copyright (C) 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 24 May 2000 <nathan@codesourcery.com> + +// we should be able to catch a base a virtual, provided it is accessible by at +// least one public path +// -- public, << private, == virtual +// E--B<<==A +// +--C--==A +// +--D<<==A + +struct A {}; +struct B : private virtual A {}; +struct C : virtual A {}; +struct D : private virtual A {}; +struct E : public B, public C, public D {}; + +extern "C" void abort (); + +void fne (E *e) +{ + throw e; +} + +void check(E *e) +{ + int caught; + + caught = 0; + try { fne(e); } + catch(A *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fne(e); } + catch(B *p) { caught = 1; if (p != e) abort();} + catch(...) { abort (); } + if (!caught) abort(); + + caught = 0; + try { fne(e); } + catch(C *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fne(e); } + catch(D *p) { caught = 1; if (p != e) abort ();} + catch(...) { abort (); } + if (!caught) abort(); + + return; +} + +int main () +{ + E e; + + check (&e); + check ((E *)0); + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch13.C b/gcc/testsuite/g++.old-deja/g++.eh/catch13.C new file mode 100644 index 000000000..2e0fdc8e7 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch13.C @@ -0,0 +1,19 @@ +// { dg-do assemble } +// { dg-options "-O2" } +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Jakub Jelinek 2 May 2001 <jakub@redhat.com> + + +struct A; + +A *foo(); + +struct A { + A *a() { try { return foo(); } catch (...) {} } + void b(); + void c(); +}; + +void A::b() { + a()->c(); +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch14.C b/gcc/testsuite/g++.old-deja/g++.eh/catch14.C new file mode 100644 index 000000000..7addb8827 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch14.C @@ -0,0 +1,33 @@ +// { dg-do assemble } +// { dg-options "-O1" } +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Jakub Jelinek 2 May 2001 <jakub@redhat.com> + + +void foo(); + +struct A { + A (int x) { }; + ~A() { + try { + foo (); + } catch (...) { } + }; +}; + +struct B; + +B *x; + +struct B { + void a(); + void b(); + static B* c() { + A y = 0; + return x; + }; +}; + +void B::a() { + c()->b(); +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch2.C b/gcc/testsuite/g++.old-deja/g++.eh/catch2.C new file mode 100644 index 000000000..3520190a0 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch2.C @@ -0,0 +1,11 @@ +// { dg-do assemble } +// Origin: Mike Danylchuk <miked@mpath.com> + +typedef char TCHAR; + +int main() +{ + try {} + catch( TCHAR* Err ) {} +} + diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch3.C b/gcc/testsuite/g++.old-deja/g++.eh/catch3.C new file mode 100644 index 000000000..2a717b36a --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch3.C @@ -0,0 +1,117 @@ +// { dg-do run } +// { dg-options "-w" } +// Copyright (C) 1999, 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 29 Aug 1999 <nathan@acm.org> + +// We cannot catch an ambiguous base class. Check with a non-virtual public +// DAG. +// -- public, << private, == virtual + +// D--B--A +// +--C--A + + +struct A { int m; }; +struct B : A { int m; }; +struct C : A { int m; }; +struct D : B, C { int m; }; + +void fna(A *obj) { throw obj; } +void fnb(B *obj) { throw obj; } +void fnc(C *obj) { throw obj; } +void fnd(D *obj) { throw obj; } + +extern "C" void abort(); + +void check(D *d) +{ + int caught; + + // try with whole object + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(D *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with an A object + caught = 0; + try { fna((B *)d); } + catch(B *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((C *)d); } + catch(C *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (C *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with B object + caught = 0; + try { fnb((B *)d); } + catch(A *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(B *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(C *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with C object + caught = 0; + try { fnc((C *)d); } + catch(A *p) { caught = 1; if (p != (C *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + return; +} + +int main () +{ + D d; + check (&d); // try with an object + check ((D *)0); // try with no object + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch3p.C b/gcc/testsuite/g++.old-deja/g++.eh/catch3p.C new file mode 100644 index 000000000..c1332b37e --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch3p.C @@ -0,0 +1,117 @@ +// { dg-do run } +// { dg-options "-w" } +// Copyright (C) 1999, 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 29 Aug 1999 <nathan@acm.org> + +// We cannot catch an ambiguous base class. Check with a non-virtual +// polymorphic public DAG. +// -- public, << private, == virtual + +// D--B--A +// +--C--A + + +struct A { int m; virtual ~A(){}}; +struct B : A { int m; }; +struct C : A { int m; }; +struct D : B, C { int m; }; + +void fna(A *obj) { throw obj; } +void fnb(B *obj) { throw obj; } +void fnc(C *obj) { throw obj; } +void fnd(D *obj) { throw obj; } + +extern "C" void abort(); + +void check(D *d) +{ + int caught; + + // try with whole object + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(D *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with an A object + caught = 0; + try { fna((B *)d); } + catch(B *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((C *)d); } + catch(C *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (C *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with B object + caught = 0; + try { fnb((B *)d); } + catch(A *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(C *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with C object + caught = 0; + try { fnc((C *)d); } + catch(A *p) { caught = 1; if (p != (C *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + return; +} + +int main () +{ + D d; + check (&d); // try with an object + check ((D *)0); // try with no object + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch4.C b/gcc/testsuite/g++.old-deja/g++.eh/catch4.C new file mode 100644 index 000000000..1da91d0ad --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch4.C @@ -0,0 +1,114 @@ +// { dg-do run } +// { dg-options "-w" } +// Copyright (C) 1999, 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 29 Aug 1999 <nathan@acm.org> + +// We cannot catch an ambiguous base class. Check with a virtual public +// DAG. +// -- public, << private, == virtual + +// D--B==A +// +--C==A + + +struct A { int m; }; +struct B : virtual A { int m; }; +struct C : virtual A { int m; }; +struct D : B, C { int m; }; + +void fna(A *obj) { throw obj; } +void fnb(B *obj) { throw obj; } +void fnc(C *obj) { throw obj; } +void fnd(D *obj) { throw obj; } + +extern "C" void abort(); + +void check(D *d) +{ + int caught; + + // try with whole object + caught = 0; + try { fnd(d); } + catch(A *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with an A object + caught = 0; + try { fna((B *)d); } + catch(B *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((C *)d); } + catch(C *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with B object + caught = 0; + try { fnb((B *)d); } + catch(A *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(C *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with C object + caught = 0; + try { fnc((C *)d); } + catch(A *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + return; +} + +int main () +{ + D d; + check (&d); // try with an object + check ((D *)0); // try with no object + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch4p.C b/gcc/testsuite/g++.old-deja/g++.eh/catch4p.C new file mode 100644 index 000000000..6700a527a --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch4p.C @@ -0,0 +1,114 @@ +// { dg-do run } +// { dg-options "-w" } +// Copyright (C) 1999, 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 29 Aug 1999 <nathan@acm.org> + +// We cannot catch an ambiguous base class. Check with a virtual +// polymorphic public DAG. +// -- public, << private, == virtual + +// D--B==A +// +--C==A + + +struct A { int m; virtual ~A(){}}; +struct B : virtual A { int m; }; +struct C : virtual A { int m; }; +struct D : B, C { int m; }; + +void fna(A *obj) { throw obj; } +void fnb(B *obj) { throw obj; } +void fnc(C *obj) { throw obj; } +void fnd(D *obj) { throw obj; } + +extern "C" void abort(); + +void check(D *d) +{ + int caught; + + // try with whole object + caught = 0; + try { fnd(d); } + catch(A *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with an A object + caught = 0; + try { fna((B *)d); } + catch(B *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((C *)d); } + catch(C *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with B object + caught = 0; + try { fnb((B *)d); } + catch(A *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(C *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with C object + caught = 0; + try { fnc((C *)d); } + catch(A *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + return; +} + +int main () +{ + D d; + check (&d); // try with an object + check ((D *)0); // try with no object + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch5.C b/gcc/testsuite/g++.old-deja/g++.eh/catch5.C new file mode 100644 index 000000000..1fae7f504 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch5.C @@ -0,0 +1,154 @@ +// { dg-do run } +// { dg-options "-w" } +// Copyright (C) 1999, 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 29 Aug 1999 <nathan@acm.org> + +// We cannot catch an ambiguous base class. +// -- public, << private, == virtual + +// D--B==A +// +--C==A +// +--AA-A + + +struct A { int m; }; +struct B : virtual A { int m; }; +struct C : virtual A { int m; }; +struct AA : A { int m; }; +struct D : B, C, AA { int m; }; + +void fna(A *obj) { throw obj; } +void fnb(B *obj) { throw obj; } +void fnc(C *obj) { throw obj; } +void fnd(D *obj) { throw obj; } +void fnaa(AA *obj) { throw obj; } + +extern "C" void abort(); + +void check(D *d) +{ + int caught; + + // try with whole object + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(D *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(AA *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with an A object + caught = 0; + try { fna((B *)d); } + catch(B *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((C *)d); } + catch(C *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (C *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((AA *)d); } + catch(AA *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (AA *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with B object + caught = 0; + try { fnb((B *)d); } + catch(A *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(C *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with C object + caught = 0; + try { fnc((C *)d); } + catch(A *p) { caught = 1; if (p != (C *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with AA object + caught = 0; + try { fnaa((AA *)d); } + catch(A *p) { caught = 1; if (p != (AA *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnaa((AA *)d); } + catch(AA *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnaa((AA *)d); } + catch(C *p) { abort(); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + return; +} + +int main () +{ + D d; + check (&d); // try with an object + check ((D *)0); // try with no object + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch5p.C b/gcc/testsuite/g++.old-deja/g++.eh/catch5p.C new file mode 100644 index 000000000..8ae8d65b4 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch5p.C @@ -0,0 +1,154 @@ +// { dg-do run } +// { dg-options "-w" } +// Copyright (C) 1999, 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 29 Aug 1999 <nathan@acm.org> + +// We cannot catch an ambiguous base class. +// -- public, << private, == virtual + +// D--B==A +// +--C==A +// +--AA-A + + +struct A { int m; virtual ~A(){}}; +struct B : virtual A { int m; }; +struct C : virtual A { int m; }; +struct AA : A { int m; }; +struct D : B, C, AA { int m; }; + +void fna(A *obj) { throw obj; } +void fnb(B *obj) { throw obj; } +void fnc(C *obj) { throw obj; } +void fnd(D *obj) { throw obj; } +void fnaa(AA *obj) { throw obj; } + +extern "C" void abort(); + +void check(D *d) +{ + int caught; + + // try with whole object + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(D *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(AA *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with an A object + caught = 0; + try { fna((B *)d); } + catch(B *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((C *)d); } + catch(C *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (C *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((AA *)d); } + catch(AA *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (AA *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with B object + caught = 0; + try { fnb((B *)d); } + catch(A *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(C *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with C object + caught = 0; + try { fnc((C *)d); } + catch(A *p) { caught = 1; if (p != (C *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with AA object + caught = 0; + try { fnaa((AA *)d); } + catch(A *p) { caught = 1; if (p != (AA *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnaa((AA *)d); } + catch(AA *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnaa((AA *)d); } + catch(C *p) { abort(); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + return; +} + +int main () +{ + D d; + check (&d); // try with an object + check ((D *)0); // try with no object + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch6.C b/gcc/testsuite/g++.old-deja/g++.eh/catch6.C new file mode 100644 index 000000000..d60d43ea9 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch6.C @@ -0,0 +1,185 @@ +// { dg-do run } +// { dg-options "-w" } +// Copyright (C) 1999, 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 29 Aug 1999 <nathan@acm.org> + +// We cannot catch an ambiguous base class. +// -- public, << private, == virtual + +// E==D--B==A +// +--C==A +// +--AA-A + + +struct A { int m; }; +struct B : virtual A { int m; }; +struct C : virtual A { int m; }; +struct AA : A { int m; }; +struct D : B, C, AA { int m; }; +struct E : virtual D { int m; }; + +void fna(A *obj) { throw obj; } +void fnb(B *obj) { throw obj; } +void fnc(C *obj) { throw obj; } +void fnd(D *obj) { throw obj; } +void fnaa(AA *obj) { throw obj; } +void fne(E *obj) { throw obj; } + +extern "C" void abort(); + +void check(E *e) +{ + int caught; + + // try with whole object + caught = 0; + try { fne(e); } + catch(A *p) { abort(); } // A is ambiguous + catch(D *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fne(e); } + catch(A *p) { abort(); } // A is ambiguous + catch(B *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fne(e); } + catch(A *p) { abort(); } // A is ambiguous + catch(C *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fne(e); } + catch(A *p) { abort(); } // A is ambiguous + catch(AA *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with D oject + caught = 0; + try { fnd((D *)e); } + catch(A *p) { abort(); } // A is ambiguous + catch(D *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd((D *)e); } + catch(A *p) { abort(); } // A is ambiguous + catch(B *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd((D *)e); } + catch(A *p) { abort(); } // A is ambiguous + catch(C *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd((D *)e); } + catch(A *p) { abort(); } // A is ambiguous + catch(AA *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with an A object + caught = 0; + try { fna((B *)e); } + catch(B *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (B *)e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((C *)e); } + catch(C *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (C *)e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((AA *)e); } + catch(AA *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (AA *)e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with B object + caught = 0; + try { fnb((B *)e); } + catch(A *p) { caught = 1; if (p != (B *)e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)e); } + catch(B *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)e); } + catch(C *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with C object + caught = 0; + try { fnc((C *)e); } + catch(A *p) { caught = 1; if (p != (C *)e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)e); } + catch(C *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)e); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with AA object + caught = 0; + try { fnaa((AA *)e); } + catch(A *p) { caught = 1; if (p != (AA *)e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnaa((AA *)e); } + catch(AA *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnaa((AA *)e); } + catch(C *p) { abort(); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + return; +} + +int main () +{ + E e; + check (&e); // try with an object + check ((E *)0); // try with no object + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch6p.C b/gcc/testsuite/g++.old-deja/g++.eh/catch6p.C new file mode 100644 index 000000000..c73ac2c41 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch6p.C @@ -0,0 +1,185 @@ +// { dg-do run } +// { dg-options "-w" } +// Copyright (C) 1999, 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 29 Aug 1999 <nathan@acm.org> + +// We cannot catch an ambiguous base class. +// -- public, << private, == virtual + +// E==D--B==A +// +--C==A +// +--AA-A + + +struct A { int m; virtual ~A(){}}; +struct B : virtual A { int m; }; +struct C : virtual A { int m; }; +struct AA : A { int m; }; +struct D : B, C, AA { int m; }; +struct E : virtual D { int m; }; + +void fna(A *obj) { throw obj; } +void fnb(B *obj) { throw obj; } +void fnc(C *obj) { throw obj; } +void fnd(D *obj) { throw obj; } +void fnaa(AA *obj) { throw obj; } +void fne(E *obj) { throw obj; } + +extern "C" void abort(); + +void check(E *e) +{ + int caught; + + // try with whole object + caught = 0; + try { fne(e); } + catch(A *p) { abort(); } // A is ambiguous + catch(D *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fne(e); } + catch(A *p) { abort(); } // A is ambiguous + catch(B *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fne(e); } + catch(A *p) { abort(); } // A is ambiguous + catch(C *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fne(e); } + catch(A *p) { abort(); } // A is ambiguous + catch(AA *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with D oject + caught = 0; + try { fnd((D *)e); } + catch(A *p) { abort(); } // A is ambiguous + catch(D *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd((D *)e); } + catch(A *p) { abort(); } // A is ambiguous + catch(B *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd((D *)e); } + catch(A *p) { abort(); } // A is ambiguous + catch(C *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd((D *)e); } + catch(A *p) { abort(); } // A is ambiguous + catch(AA *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with an A object + caught = 0; + try { fna((B *)e); } + catch(B *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (B *)e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((C *)e); } + catch(C *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (C *)e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((AA *)e); } + catch(AA *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (AA *)e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with B object + caught = 0; + try { fnb((B *)e); } + catch(A *p) { caught = 1; if (p != (B *)e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)e); } + catch(B *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)e); } + catch(C *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with C object + caught = 0; + try { fnc((C *)e); } + catch(A *p) { caught = 1; if (p != (C *)e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)e); } + catch(C *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)e); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with AA object + caught = 0; + try { fnaa((AA *)e); } + catch(A *p) { caught = 1; if (p != (AA *)e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnaa((AA *)e); } + catch(AA *p) { caught = 1; if (p != e) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnaa((AA *)e); } + catch(C *p) { abort(); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + return; +} + +int main () +{ + E e; + check (&e); // try with an object + check ((E *)0); // try with no object + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch7.C b/gcc/testsuite/g++.old-deja/g++.eh/catch7.C new file mode 100644 index 000000000..936b67ca7 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch7.C @@ -0,0 +1,184 @@ +// { dg-do run } +// { dg-options "-w" } +// Copyright (C) 1999, 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 29 Aug 1999 <nathan@acm.org> + +// We cannot catch an ambiguous base class. +// -- public, << private, == virtual + +// different levels +// F--D--B--A +// +--C--A +// +--E--A + + +struct A { int m; }; +struct B : A { int m; }; +struct C : A { int m; }; +struct D : B, C { int m; }; +struct E : A { int m; }; +struct F : D, E { int m; }; + +void fna(A *obj) { throw obj; } +void fnb(B *obj) { throw obj; } +void fnc(C *obj) { throw obj; } +void fnd(D *obj) { throw obj; } +void fne(E *obj) { throw obj; } +void fnf(F *obj) { throw obj; } + +extern "C" void abort(); + +void check(F *f) +{ + int caught; + + // try with whole object + caught = 0; + try { fnf(f); } + catch(A *p) { abort(); } // A is ambiguous + catch(F *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnf(f); } + catch(A *p) { abort(); } // A is ambiguous + catch(E *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnf(f); } + catch(A *p) { abort(); } // A is ambiguous + catch(D *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnf(f); } + catch(A *p) { abort(); } // A is ambiguous + catch(B *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnf(f); } + catch(A *p) { abort(); } // A is ambiguous + catch(C *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with D object + caught = 0; + try { fnd(f); } + catch(A *p) { abort(); } // A is ambiguous + catch(D *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(f); } + catch(A *p) { abort(); } // A is ambiguous + catch(B *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(f); } + catch(A *p) { abort(); } // A is ambiguous + catch(C *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with E object + caught = 0; + try { fne(f); } + catch(A *p) { caught = 1; if (p != (E *)f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fne(f); } + catch(E *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fne(f); } + catch(F *p) { abort(); } + catch(...) { caught = 1; } + if (!caught) abort(); + + // try with an A object + caught = 0; + try { fna((B *)f); } + catch(B *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (B *)f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((C *)f); } + catch(C *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (C *)f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((E *)f); } + catch(E *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (E *)f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with B object + caught = 0; + try { fnb((B *)f); } + catch(A *p) { caught = 1; if (p != (B *)f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)f); } + catch(B *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)f); } + catch(C *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with C object + caught = 0; + try { fnc((C *)f); } + catch(A *p) { caught = 1; if (p != (C *)f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)f); } + catch(C *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)f); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + return; +} + +int main () +{ + F f; + check (&f); // try with an object + check ((F *)0); // try with no object + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch7p.C b/gcc/testsuite/g++.old-deja/g++.eh/catch7p.C new file mode 100644 index 000000000..5f15a48fc --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch7p.C @@ -0,0 +1,184 @@ +// { dg-do run } +// { dg-options "-w" } +// Copyright (C) 1999, 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 29 Aug 1999 <nathan@acm.org> + +// We cannot catch an ambiguous base class. +// -- public, << private, == virtual + +// different levels +// F--D--B--A +// +--C--A +// +--E--A + + +struct A { int m; virtual ~A(){}}; +struct B : A { int m; }; +struct C : A { int m; }; +struct D : B, C { int m; }; +struct E : A { int m; }; +struct F : D, E { int m; }; + +void fna(A *obj) { throw obj; } +void fnb(B *obj) { throw obj; } +void fnc(C *obj) { throw obj; } +void fnd(D *obj) { throw obj; } +void fne(E *obj) { throw obj; } +void fnf(F *obj) { throw obj; } + +extern "C" void abort(); + +void check(F *f) +{ + int caught; + + // try with whole object + caught = 0; + try { fnf(f); } + catch(A *p) { abort(); } // A is ambiguous + catch(F *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnf(f); } + catch(A *p) { abort(); } // A is ambiguous + catch(E *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnf(f); } + catch(A *p) { abort(); } // A is ambiguous + catch(D *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnf(f); } + catch(A *p) { abort(); } // A is ambiguous + catch(B *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnf(f); } + catch(A *p) { abort(); } // A is ambiguous + catch(C *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with D object + caught = 0; + try { fnd(f); } + catch(A *p) { abort(); } // A is ambiguous + catch(D *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(f); } + catch(A *p) { abort(); } // A is ambiguous + catch(B *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(f); } + catch(A *p) { abort(); } // A is ambiguous + catch(C *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with E object + caught = 0; + try { fne(f); } + catch(A *p) { caught = 1; if (p != (E *)f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fne(f); } + catch(E *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fne(f); } + catch(F *p) { abort(); } + catch(...) { caught = 1; } + if (!caught) abort(); + + // try with an A object + caught = 0; + try { fna((B *)f); } + catch(B *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (B *)f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((C *)f); } + catch(C *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (C *)f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((E *)f); } + catch(E *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (E *)f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with B object + caught = 0; + try { fnb((B *)f); } + catch(A *p) { caught = 1; if (p != (B *)f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)f); } + catch(B *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)f); } + catch(C *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with C object + caught = 0; + try { fnc((C *)f); } + catch(A *p) { caught = 1; if (p != (C *)f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)f); } + catch(C *p) { caught = 1; if (p != f) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)f); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + return; +} + +int main () +{ + F f; + check (&f); // try with an object + check ((F *)0); // try with no object + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch8.C b/gcc/testsuite/g++.old-deja/g++.eh/catch8.C new file mode 100644 index 000000000..1947c1c02 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch8.C @@ -0,0 +1,110 @@ +// { dg-do run } +// { dg-options "-w" } +// Copyright (C) 1999, 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 6 Jun 1999 <nathan@acm.org> + +// We cannot catch an ambiguous base class. +// -- public, << private, == virtual + +// D--B--A +// +--C<<A + + +struct A { int m; }; +struct B : A { int m; }; +struct C : private A { int m; }; +struct D : B, C { int m; }; + +void fna(A *obj) { throw obj; } +void fnb(B *obj) { throw obj; } +void fnc(C *obj) { throw obj; } +void fnd(D *obj) { throw obj; } + +extern "C" void abort(); + +void check(D *d) +{ + int caught; + + // try with whole object + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(D *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with an A object + caught = 0; + try { fna((B *)d); } + catch(B *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((A *)(C *)d); } + catch(C *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (A *)(C *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with B object + caught = 0; + try { fnb((B *)d); } + catch(A *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(C *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(A *p) { abort();} + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + return; +} + +int main () +{ + D d; + check (&d); // try with an object + check ((D *)0); // try with no object + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch8p.C b/gcc/testsuite/g++.old-deja/g++.eh/catch8p.C new file mode 100644 index 000000000..56fafcf98 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch8p.C @@ -0,0 +1,111 @@ +// { dg-do run } +// { dg-options "-w" } +// Copyright (C) 1999, 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 6 Jun 1999 <nathan@acm.org> + +// We cannot catch an ambiguous base class. +// -- public, << private, == virtual + +// D--B--A +// +--C<<A + + +struct A { int m; virtual ~A(){}}; +struct B : A { int m; }; +struct C : private A { int m; }; +struct D : B, C { int m; }; + +void fna(A *obj) { throw obj; } +void fnb(B *obj) { throw obj; } +void fnc(C *obj) { throw obj; } +void fnd(D *obj) { throw obj; } + +extern "C" void abort(); + +void check(D *d) +{ + int caught; + + // try with whole object + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(D *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with an A object + caught = 0; + try { fna((B *)d); } + catch(B *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((A *)(C *)d); } + catch(C *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (A *)(C *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with B object + caught = 0; + try { fnb((B *)d); } + catch(A *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(C *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with C object + caught = 0; + try { fnc((C *)d); } + catch(A *p) { abort();} + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + return; +} + +int main () +{ + D d; + check (&d); // try with an object + check ((D *)0); // try with no object + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch9.C b/gcc/testsuite/g++.old-deja/g++.eh/catch9.C new file mode 100644 index 000000000..f4938a398 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch9.C @@ -0,0 +1,117 @@ +// { dg-do run } +// { dg-options "-w" } +// Copyright (C) 1999, 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 29 Aug 1999 <nathan@acm.org> + +// We cannot catch an ambiguous base class. +// -- public, << private, == virtual + +// D==B--A +// +==C--A + + +struct A { int m; }; +struct B : A { int m; }; +struct C : A { int m; }; +struct D : virtual B, virtual C { int m; }; + + +void fna(A *obj) { throw obj; } +void fnb(B *obj) { throw obj; } +void fnc(C *obj) { throw obj; } +void fnd(D *obj) { throw obj; } + +extern "C" void abort(); + +void check(D *d) +{ + int caught; + + // try with whole object + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(D *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with an A object + caught = 0; + try { fna((B *)d); } + catch(B *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((C *)d); } + catch(C *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (C *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with B object + caught = 0; + try { fnb((B *)d); } + catch(A *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(B *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(C *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with C object + caught = 0; + try { fnc((C *)d); } + catch(A *p) { caught = 1; if (p != (C *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(C *p) { caught = 1; if (p != (C *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + return; +} + +int main () +{ + D d; + check (&d); // try with an object + check ((D *)0); // try with no object + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catch9p.C b/gcc/testsuite/g++.old-deja/g++.eh/catch9p.C new file mode 100644 index 000000000..9cec7e7d6 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catch9p.C @@ -0,0 +1,117 @@ +// { dg-do run } +// { dg-options "-w" } +// Copyright (C) 1999, 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 29 Aug 1999 <nathan@acm.org> + +// We cannot catch an ambiguous base class. +// -- public, << private, == virtual + +// D==B--A +// +==C--A + + +struct A { int m; virtual ~A(){}}; +struct B : A { int m; }; +struct C : A { int m; }; +struct D : virtual B, virtual C { int m; }; + + +void fna(A *obj) { throw obj; } +void fnb(B *obj) { throw obj; } +void fnc(C *obj) { throw obj; } +void fnd(D *obj) { throw obj; } + +extern "C" void abort(); + +void check(D *d) +{ + int caught; + + // try with whole object + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(D *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnd(d); } + catch(A *p) { abort(); } // A is ambiguous + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with an A object + caught = 0; + try { fna((B *)d); } + catch(B *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fna((C *)d); } + catch(C *p) { abort(); } // throw type is static type + catch(A *p) { caught = 1; if (p != (C *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + // try with B object + caught = 0; + try { fnb((B *)d); } + catch(A *p) { caught = 1; if (p != (B *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(B *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnb((B *)d); } + catch(C *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + // try with C object + caught = 0; + try { fnc((C *)d); } + catch(A *p) { caught = 1; if (p != (C *)d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(C *p) { caught = 1; if (p != d) abort();} + catch(...) { abort(); } + if (!caught) abort(); + + caught = 0; + try { fnc((C *)d); } + catch(B *p) { abort(); } + catch(D *p) { abort(); } + catch(...) { caught =1; } + if (!caught) abort(); + + return; +} + +int main () +{ + D d; + check (&d); // try with an object + check ((D *)0); // try with no object + + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/catchptr1.C b/gcc/testsuite/g++.old-deja/g++.eh/catchptr1.C new file mode 100644 index 000000000..2d2467548 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/catchptr1.C @@ -0,0 +1,262 @@ +// { dg-do run } +// Test pointer chain catching +// Copyright (C) 2000, 2002 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 9 Apr 2000 <nathan@nathan@codesourcery.com> + +#include <stdio.h> + +void fn () {} +struct A {void fn () {}}; +static int var = 1; +static const int const_var = 2; + +struct B; +struct C; + +int test0 () +{ + try + { + throw &fn; + } + catch (void *) + { + // should not decay to void * + return 1; + } + catch (...) + { + return 0; + } + return -1; +} + +int test1 () +{ + try + { + throw &A::fn; + } + catch (void *) + { + // should not decay to void * + return 1; + } + catch (...) + { + return 0; + } + return -1; +} + +int test2 () +{ + try + { + throw &var; + } + catch (void *) + { + // should decay to void * + return 0; + } + catch (...) + { + return 1; + } + return -1; +} + +int test3 () +{ + try + { + throw &var; + } + catch (void const *) + { + // should decay to const void * + return 0; + } + catch (...) + { + return 1; + } + return -1; +} + +int test4 () +{ + try + { + throw &const_var; + } + catch (void *) + { + // should not decay to void * + return 1; + } + catch (void const *) + { + // should decay to const void * + return 0; + } + catch (...) + { + return 2; + } + return -1; +} + +int test5 () +{ + try + { + throw (void ***)0; + } + catch (void ***) + { + return 0; + } + catch (...) + { + return 1; + } + return -1; +} + +int test6 () +{ + try + { + throw (void const* const* const*)0; + } + catch (void ***) + { + return 1; + } + catch (void * const* const*) + { + return 2; + } + catch (void const* * const*) + { + return 3; + } + catch (void const* const* *) + { + return 4; + } + catch (void const* const* const *) + { + return 0; + } + catch (...) + { + return 1; + } + return -1; +} + +int test7 () +{ + try + { + throw (void ***)0; + } + catch (void const* const**) + { + return 1; + } + catch (void const** const *) + { + return 2; + } + catch (void * const* const *) + { + return 0; + } + catch (...) + { + return 3; + } + return -1; +} + +int test8 () +{ + try + { + throw (B **)0; + } + catch (C **) + { + return 1; + } + catch (B **) + { + return 0; + } + catch (...) + { + return 2; + } + return -1; +} + +int test9 () +{ + try + { + throw (B **)0; + } + catch (C const *const *) + { + return 1; + } + catch (B const *const *) + { + return 0; + } + catch (...) + { + return 2; + } + return -1; +} + +static int (*tests[])() = +{ + test0, + test1, + test2, + test3, + test4, + + test5, + test6, + test7, + + test8, + test9, + + NULL +}; + +int main () +{ + int ix; + int errors = 0; + + for (ix = 0; tests[ix]; ix++) + { + int n = tests[ix] (); + + if (n) + { + printf ("test %d failed %d\n", ix, n); + errors++; + } + } + return errors; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/cleanup1.C b/gcc/testsuite/g++.old-deja/g++.eh/cleanup1.C new file mode 100644 index 000000000..16646438e --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/cleanup1.C @@ -0,0 +1,35 @@ +// { dg-do run } +// Bug: obj gets destroyed twice because the fixups for the return are +// inside its cleanup region. + +extern "C" int printf (const char *, ...); + +int d; + +struct myExc { }; + +struct myExcRaiser { + ~myExcRaiser() { throw myExc(); } +}; + +struct stackObj { + ~stackObj() { ++d; printf ("stackObj::~stackObj()\n"); } +}; + +int test() +{ + myExcRaiser rais; + stackObj obj; + return 0; +} + +int main() +{ + try { + test(); + } + catch (myExc &) { + return d != 1; + } + return 1; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/cleanup2.C b/gcc/testsuite/g++.old-deja/g++.eh/cleanup2.C new file mode 100644 index 000000000..9538de961 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/cleanup2.C @@ -0,0 +1,53 @@ +// { dg-do run } +// Copyright (C) 1999 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 21 Nov 1999 <nathan@acm.org> + +// make sure we don't call base dtors, if we failed to call the +// base ctor due to exception throwing + +#include <stdio.h> + +static bool bad = false; + +static int thrower () +{ + printf ("in %s\n", __PRETTY_FUNCTION__); + throw 0; + return 0; +} + +struct X +{ + X (int) throw (int); + ~X () throw (); +}; + +X::X (int) throw (int) + {printf ("in ctor X %s\n", __PRETTY_FUNCTION__); bad = true;} +X::~X () throw () + {printf ("in dtor X %s\n", __PRETTY_FUNCTION__); bad = true;} + +struct X1 {}; +struct Y : X +{ + Y() throw (int); + ~Y() throw (); +}; +Y::Y() throw (int) + : X(thrower ()) // throws, so X::X is never called + {printf ("in ctor Y%s\n", __PRETTY_FUNCTION__); bad = true;} +Y::~Y() throw () + {printf ("in dtor Y%s\n", __PRETTY_FUNCTION__); bad = true;} + +int main () +{ + try + { + Y y; + } + catch (...) + { + printf ("caught\n"); + } + return bad; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/cond1.C b/gcc/testsuite/g++.old-deja/g++.eh/cond1.C new file mode 100644 index 000000000..1b2de1d10 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/cond1.C @@ -0,0 +1,31 @@ +// { dg-do assemble } + +// Copyright (C) 1999, 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 11 Apr 1999 <nathan@acm.org> +// Derived from bug report from Gabriel Dos Reis +// <Gabriel.Dos-Reis@cmla.ens-cachan.fr> +// http://gcc.gnu.org/ml/gcc-bugs/1999-03n/msg00888.html + +// conditional exprs have some funny rules when one of the types is void. +// [expr.cond] 5.16, make sure we do the right things +// We implement an extension, allowing one side to be void, check we +// pedantically moan. + +struct X {}; +void fn(int i) +{ + int j; + + j = (i ? throw X() : 1); // ok, int + j = (i ? 1 : throw X()); // ok, int + + (i ? throw X() : throw X()); // ok, void + + (i ? i : j) = 1; // ok, int & + (i ? throw X() : j) = 1; // { dg-error "" } non-lvalue + (i ? j : throw X()) = 1; // { dg-error "" } non-lvalue + (i ? throw X() : throw X()) = 1; // { dg-error "" } void + + (i ? (void)1 : i++); // { dg-error "" } ANSI forbids + (i ? i++ : (void)1); // { dg-error "" } ANSI forbids +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/crash1.C b/gcc/testsuite/g++.old-deja/g++.eh/crash1.C new file mode 100644 index 000000000..a4440c7bd --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/crash1.C @@ -0,0 +1,22 @@ +// { dg-do assemble } +// { dg-options "-O1 -fno-inline-functions" } + +struct A +{ + ~A (); +}; + +bool foo (); + +int i; +int j; + +A bar () +{ + for (i = 0; i < 1; ++i) + if (j) + { + A tmp; + return tmp; + } +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/crash2.C b/gcc/testsuite/g++.old-deja/g++.eh/crash2.C new file mode 100644 index 000000000..195b8623c --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/crash2.C @@ -0,0 +1,27 @@ +// { dg-do assemble } +// { dg-options "-O" } +// Origin: Thomas Kunert <kunert@physik.tu-dresden.de> + +struct C { + ~C(); +}; + +struct R { + bool empty() const; + C m_; +}; + +struct R1 { + R1( const R& a ); + ~R1 (); + C m_; +}; + +R1 get_empty(); + +R1::R1( const R& a ) : + m_( a.empty() ? get_empty().m_ : C() ) +{} + +void qnorm( const R & r) +{ R1 n( r ); } diff --git a/gcc/testsuite/g++.old-deja/g++.eh/crash3.C b/gcc/testsuite/g++.old-deja/g++.eh/crash3.C new file mode 100644 index 000000000..e0cc42036 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/crash3.C @@ -0,0 +1,16 @@ +// { dg-do assemble } +// Origin: Marc Espie <Marc.Espie@liafa.jussieu.fr> +// Used to use -fsjlj-exceptions, but that isn't an option anymore. + +extern double f(double a); + +void +a() +{ + double e; + double value; + + if (e == 0) + throw 1; + value = f(e); +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/crash4.C b/gcc/testsuite/g++.old-deja/g++.eh/crash4.C new file mode 100644 index 000000000..e14f03b07 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/crash4.C @@ -0,0 +1,14 @@ +// { dg-do assemble } +// { dg-options "-O2" } +// Origin: Nathan Sidwell <nathan@codesourcery.com> + +struct A +{ + A (int) { } + ~A () { } + int get () const { return 0; } +}; + +void f (const A &s) { + f (s.get ()); +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/crash5.C b/gcc/testsuite/g++.old-deja/g++.eh/crash5.C new file mode 100644 index 000000000..eceb22ed1 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/crash5.C @@ -0,0 +1,12 @@ +// { dg-do assemble } +// Origin: Mark Mitchell <mark@codesourcery.com> + +int i; +int j; + +void +f () +{ + j = j + (i ? 7 : throw 1); +} + diff --git a/gcc/testsuite/g++.old-deja/g++.eh/crash6.C b/gcc/testsuite/g++.old-deja/g++.eh/crash6.C new file mode 100644 index 000000000..7151cbfe3 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/crash6.C @@ -0,0 +1,26 @@ +// { dg-do assemble } +// +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 26 April 2001 <nathan@codesourcery.com> +// Origin: schmid@snake.iap.physik.tu-darmstadt.de + +// Bug 2368. When checking shadowed catchers, we didn't ignore +// template type parms etc, leading to an ICE + +template<class CatchType1, class CatchType2> +void call(int& a) +{ + try + { + + } + catch (CatchType1&) + { + + } + catch (CatchType2&) + { + + } +} + diff --git a/gcc/testsuite/g++.old-deja/g++.eh/ctor1.C b/gcc/testsuite/g++.old-deja/g++.eh/ctor1.C new file mode 100644 index 000000000..0e7218f0c --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/ctor1.C @@ -0,0 +1,18 @@ +// { dg-do assemble } +struct A +{ + A(); // { dg-message "A::A|candidate expects" } candidate + A(A&); // { dg-message "A::A|no known conversion" } referenced below +}; + +int +main () +{ + try + { + throw A(); // { dg-error "no matching" "match" } can't copy + // { dg-message "candidate" "candidate note" { target *-*-* } 13 } +// { dg-error "thrown expression" "expr" { target *-*-* } 13 } + } + catch (...) { } +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/flow1.C b/gcc/testsuite/g++.old-deja/g++.eh/flow1.C new file mode 100644 index 000000000..d48a896b2 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/flow1.C @@ -0,0 +1,23 @@ +// { dg-do run } +#include <stdio.h> + +int bar () +{ + throw 100; + return 0; +} + +int main () +{ + int i = 0; // this gets deleted after flow analysis + try + { + i = bar (); + } + catch (...) + { + } + + printf ("i = %d\n", i); + return i; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/fntry1.C b/gcc/testsuite/g++.old-deja/g++.eh/fntry1.C new file mode 100644 index 000000000..9b14f0111 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/fntry1.C @@ -0,0 +1,32 @@ +// { dg-do run } +// Bug: g++ fails to treat function-try-blocks in ctors specially. +// Submitted by Jason Merrill <jason@cygnus.com> + +int c; +int r; + +struct A { + int i; + A(int j) { i = j; } + ~A() { c += i; } +}; + +struct B: public A { + A a; + B() try : A(1), a(2) + { throw 1; } + catch (...) + { if (c != 3) r |= 1; } +}; + +int main () +{ + try + { B b; } + catch (...) + { c = 0; } + + if (c != 0) r |= 2; + + return r; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/ia64-1.C b/gcc/testsuite/g++.old-deja/g++.eh/ia64-1.C new file mode 100644 index 000000000..f8def11d6 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/ia64-1.C @@ -0,0 +1,73 @@ +// { dg-do run } +// { dg-options "-O2" } + +#include <exception> + +using namespace std; + +extern "C" void abort(); + +int i_0, i_1, i_2, i_3, i_4, i_5, i_6, i_7, i_8, i_9; +int j_0, j_1, j_2, j_3, j_4, j_5, j_6, j_7, j_8, j_9; +int k_0, k_1, k_2, k_3, k_4, k_5, k_6, k_7, k_8, k_9; +int l_0, l_1, l_2, l_3, l_4, l_5, l_6, l_7, l_8, l_9; +#define A(x,y,n) register int *x##n = &y##_##n; +#define B(x,y) \ + A(x,y,0) A(x,y,1) A(x,y,2) A(x,y,3) A(x,y,4) \ + A(x,y,5) A(x,y,6) A(x,y,7) A(x,y,8) A(x,y,9) +#define C(x,n) asm volatile ("" : "=r" (x##n) : "0" (x##n)); +#define D(x) \ + C(x,0) C(x,1) C(x,2) C(x,3) C(x,4) \ + C(x,5) C(x,6) C(x,7) C(x,8) C(x,9) +#define E(x,y,n) if (x##n != &y##_##n) abort (); +#define F(x,y) \ + E(x,y,0) E(x,y,1) E(x,y,2) E(x,y,3) E(x,y,4) \ + E(x,y,5) E(x,y,6) E(x,y,7) E(x,y,8) E(x,y,9) + +void bar(long a0, long a1, long a2, long a3, long a4) +{ +} + +void foo(long a0, long a1, long a2, long a3, long a4) +{ + A(p,l,0) A(p,l,1) A(p,l,2) + C(p,0) C(p,1) C(p,2) + bar (0, 1, 2, 3, 4); + if (a0 == 0) + throw exception(); + C(p,0) C(p,1) C(p,2) + E(p,l,0) E(p,l,1) E(p,l,2) +} + +void test(void) +{ + A(p,l,0) A(p,l,1) A(p,l,2) A(p,l,3) A(p,l,4) A(p,l,5) A(p,l,6) + C(p,0) C(p,1) C(p,2) C(p,3) C(p,4) C(p,5) C(p,6) + try { + foo(0, 1, 2, 3, 4); + } catch (exception) {} + C(p,0) C(p,1) C(p,2) C(p,3) C(p,4) C(p,5) C(p,6) + E(p,l,0) E(p,l,1) E(p,l,2) E(p,l,3) E(p,l,4) E(p,l,5) E(p,l,6) +} + +int main() +{ + B(x,i) + B(y,j) + B(z,k) + A(p,l,0) A(p,l,1) A(p,l,2) A(p,l,3) + D(x) + D(y) + D(z) + C(p,0) C(p,1) C(p,2) C(p,3) + test(); + D(x) + D(y) + D(z) + C(p,0) C(p,1) C(p,2) C(p,3) + F(x,i) + F(y,j) + F(z,k) + E(p,l,0) E(p,l,1) E(p,l,2) E(p,l,3) + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/inline1.C b/gcc/testsuite/g++.old-deja/g++.eh/inline1.C new file mode 100644 index 000000000..e35976757 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/inline1.C @@ -0,0 +1,25 @@ +// { dg-do assemble } +// { dg-options "-ansi -pedantic-errors -O2" } +// Copyright (C) 1999 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 29 Nov 1999 <nathan@acm.org> + + +struct Foo +{ + inline ~Foo (); +}; + +inline void Wibble (int) throw () +{ +} + +inline Foo::~Foo () +{ + Wibble (6); +} + +int ExtendFoos () +{ + Foo tmp; + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/inline2.C b/gcc/testsuite/g++.old-deja/g++.eh/inline2.C new file mode 100644 index 000000000..356c85a7c --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/inline2.C @@ -0,0 +1,25 @@ +// { dg-do run } +// { dg-options "-O" } +// Test that inlining a destructor with a catch block doesn't confuse the +// enclosing try block. + +struct A { + ~A() + { + try { throw 1; } + catch (...) { } + } +}; + +int main () +{ + try + { + A a; + throw 42; + } + catch (int i) + { + return (i != 42); + } +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/new1.C b/gcc/testsuite/g++.old-deja/g++.eh/new1.C new file mode 100644 index 000000000..4c52cf40e --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/new1.C @@ -0,0 +1,49 @@ +// { dg-do run } +// Test that a throw in foo destroys the A, but does not free the memory. + +#include <cstddef> +#include <cstdlib> +#include <new> + +struct A { + A(); + ~A(); +}; + +struct B { + B (A); +}; + +void foo (B*); + +int newed, created; + +int main () +{ + try { + foo (new B (A ())); + } catch (...) { } + + return !(newed && !created); +} + +A::A() { created = 1; } +A::~A() { created = 0; } +B::B(A) { } +void foo (B*) { throw 1; } + +void* operator new (size_t size) throw (std::bad_alloc) +{ + ++newed; + return (void *) std::malloc (size); +} + +void operator delete (void *p) throw () +{ + --newed; + std::free (p); +} + + + + diff --git a/gcc/testsuite/g++.old-deja/g++.eh/new2.C b/gcc/testsuite/g++.old-deja/g++.eh/new2.C new file mode 100644 index 000000000..2d69df0e7 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/new2.C @@ -0,0 +1,47 @@ +// { dg-do run } +// Test that a throw in B's constructor destroys the A and frees the memory. + +#include <cstddef> +#include <cstdlib> +#include <new> + +struct A { + A(); + ~A(); +}; + +struct B { + B (A); +}; + +void foo (B*); + +int newed, created; + +int main () +{ + newed = 0; // The libraries might call new before main starts. + try { + foo (new B (A ())); + } catch (...) { } + + return !(!newed && !created); +} + +A::A() { created = 1; } +A::~A() { created = 0; } +B::B(A) { throw 1; } +void foo (B*) { } + +void* operator new (size_t size) throw (std::bad_alloc) +{ + ++newed; + return (void *) std::malloc (size); +} + +void operator delete (void *p) throw () +{ + --newed; + free (p); +} + diff --git a/gcc/testsuite/g++.old-deja/g++.eh/pdel1.C b/gcc/testsuite/g++.old-deja/g++.eh/pdel1.C new file mode 100644 index 000000000..fd7ecff3c --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/pdel1.C @@ -0,0 +1,23 @@ +// { dg-do run } +// Test for calling placement delete. + +#include <new> +#include <stddef.h> + +int r = 1; + +struct A { + A() { throw 1; } + void operator delete (void *p, int, int) { r = 0; ::operator delete (p); } +}; + +void * operator new (size_t size, int, int) { return operator new (size); } + +int main () +{ + try { + A* ap = new (1, 5) A; + } catch (...) { } + + return r; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/pdel2.C b/gcc/testsuite/g++.old-deja/g++.eh/pdel2.C new file mode 100644 index 000000000..9bad6eea4 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/pdel2.C @@ -0,0 +1,23 @@ +// { dg-do run } +// Test for not calling mismatched placement delete. + +#include <new> +#include <stddef.h> + +int r = 0; + +struct A { + A() { throw 1; } + void operator delete (void *p, int, long) { r = 1; ::operator delete (p); } +}; + +void * operator new (size_t size, int, int) { return operator new (size); } + +int main () +{ + try { + A* ap = new (1, 5) A; + } catch (...) { } + + return r; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/ptr1.C b/gcc/testsuite/g++.old-deja/g++.eh/ptr1.C new file mode 100644 index 000000000..aefe5cc61 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/ptr1.C @@ -0,0 +1,23 @@ +// { dg-do run } +// Bug: catching pointers by reference doesn't work right. + +extern "C" int printf (const char *, ...); + +struct E { + int x; + E(int i) { x = i; } +}; + +int main() +{ + try { + E *p = new E(5); + throw p; + } + + catch (E *&e) { + printf ("address of e is 0x%lx\n", (__SIZE_TYPE__)e); + return !((__SIZE_TYPE__)e != 5 && e->x == 5); + } + return 2; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/ptrmem1.C b/gcc/testsuite/g++.old-deja/g++.eh/ptrmem1.C new file mode 100644 index 000000000..299dc4a05 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/ptrmem1.C @@ -0,0 +1,16 @@ +// { dg-do run } +extern "C" void exit (int); +extern "C" void abort (void); +struct A { int i; }; +int main () +{ + try { throw &A::i; } + catch (int A::*p) + { + if (p == &A::i) + exit (0); + else + abort (); + } + abort (); +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/rethrow1.C b/gcc/testsuite/g++.old-deja/g++.eh/rethrow1.C new file mode 100644 index 000000000..286f1bd25 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/rethrow1.C @@ -0,0 +1,46 @@ +// { dg-do run } +// Testcase for proper handling of rethrow. + +#include <stdio.h> + +int c, d; + +struct A +{ + int i; + A () { i = ++c; printf ("A() %d\n", i); } + A (const A&) { i = ++c; printf ("A(const A&) %d\n", i); } + ~A() { printf ("~A() %d\n", i); ++d; } +}; + +int +main () +{ + try + { + try + { + printf ("Throwing 1...\n"); + throw A(); + } + catch (A) + { + try + { + printf ("Throwing 2...\n"); + throw A(); + } + catch (A) + { + printf ("Throwing 3...\n"); + throw; + } + } + } + catch (A) + { + printf ("Caught.\n"); + } + printf ("c == %d, d == %d\n", c, d); + return c != d; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/rethrow2.C b/gcc/testsuite/g++.old-deja/g++.eh/rethrow2.C new file mode 100644 index 000000000..cd2dd7e47 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/rethrow2.C @@ -0,0 +1,46 @@ +// { dg-do run } +// Testcase for proper handling of rethrow. + +#include <stdio.h> + +int c, d; + +struct A +{ + int i; + A () { i = ++c; printf ("A() %d\n", i); } + A (const A&) { i = ++c; printf ("A(const A&) %d\n", i); } + ~A() { printf ("~A() %d\n", i); ++d; } +}; + +int +main () +{ + try + { + try + { + printf ("Throwing 1...\n"); + throw A(); + } + catch (A) + { + try + { + printf ("Throwing 2...\n"); + throw; + } + catch (A) + { + printf ("Throwing 3...\n"); + throw; + } + } + } + catch (A) + { + printf ("Caught.\n"); + } + printf ("c == %d, d == %d\n", c, d); + return c != d; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/rethrow3.C b/gcc/testsuite/g++.old-deja/g++.eh/rethrow3.C new file mode 100644 index 000000000..952318b80 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/rethrow3.C @@ -0,0 +1,40 @@ +// { dg-do run } +#include <stdio.h> +#include <stdlib.h> +#include <exception> + +static void +eh_terminate () +{ + printf ("CALLING TERMINATE\n"); + exit (1); +} + +void +eh_test (int level) +{ + try + { + if (level < 2) + eh_test (level + 1); + else + { + printf ("%d: Throwing\n", level); + throw (level); + } + } + catch (int &x) + { + printf ("%d: Got level %d\n", + level, x); + + if (level > 0) + throw; + } +} + +int main () +{ + std::set_terminate (&eh_terminate); + eh_test (0); +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/rethrow4.C b/gcc/testsuite/g++.old-deja/g++.eh/rethrow4.C new file mode 100644 index 000000000..df54e4931 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/rethrow4.C @@ -0,0 +1,46 @@ +// { dg-do run } +// Testcase for proper handling of rethrow. + +#include <stdio.h> + +int c, d; + +struct A +{ + int i; + A () { i = ++c; printf ("A() %d\n", i); } + A (const A&) { i = ++c; printf ("A(const A&) %d\n", i); } + ~A() { printf ("~A() %d\n", i); ++d; } +}; + +int +main () +{ + try + { + try + { + printf ("Throwing 1...\n"); + throw A(); + } + catch (A) + { + try + { + printf ("Throwing 2...\n"); + throw; + } + catch (A) + { + printf ("Throwing 3...\n"); + throw A(); + } + } + } + catch (A) + { + printf ("Caught.\n"); + } + printf ("c == %d, d == %d\n", c, d); + return c != d; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/rethrow5.C b/gcc/testsuite/g++.old-deja/g++.eh/rethrow5.C new file mode 100644 index 000000000..34a56e41f --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/rethrow5.C @@ -0,0 +1,45 @@ +// { dg-do run } +// Testcase for proper handling of rethrow. + +#include <stdio.h> + +int c, d; + +struct A +{ + int i; + A () { i = ++c; printf ("A() %d\n", i); } + A (const A&) { i = ++c; printf ("A(const A&) %d\n", i); } + ~A() { printf ("~A() %d\n", i); ++d; } +}; + +int +main () +{ + try + { + try + { + printf ("Throwing 1...\n"); + throw A(); + } + catch (A) + { + try + { + printf ("Throwing 2...\n"); + throw; + } + catch (A) + { + printf ("Falling out...\n"); + } + } + } + catch (A) + { + printf ("Caught.\n"); + } + printf ("c == %d, d == %d\n", c, d); + return c != d; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/rethrow6.C b/gcc/testsuite/g++.old-deja/g++.eh/rethrow6.C new file mode 100644 index 000000000..ce9962605 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/rethrow6.C @@ -0,0 +1,76 @@ +// { dg-do run } +// Testcase for proper handling of rethrow. + +#include <stdio.h> + +int c, d; +int wrong; + +struct A +{ + int i; + A () { i = c++; printf ("A() %d\n", i); } + A (const A&) { i = c++; printf ("A(const A&) %d\n", i); } + ~A() { printf ("~A() %d\n", i); ++d; } +}; + +struct B +{ + ~B () { + try + { + printf ("Rethrowing III...\n"); + throw; + } + catch (A& a) + { + printf ("Caught III %d...\n", a.i); + if (a.i != 1) + { + printf ("** rethrew uncaught exception **\n"); + wrong = 1; + } + } + printf ("continuing to unwind II...\n"); + } +}; + +int +main () +{ + { + A a; + + try + { + try + { + printf ("Throwing I...\n"); + throw a; + } + catch (A& a) + { + printf ("Caught I %d...\n", a.i); + try + { + B b; + printf ("Throwing II...\n"); + throw a; + } + catch (A& a) + { + printf ("Caught II %d...\n", a.i); + printf ("Throwing IV...\n"); + throw; + } + } + } + catch (A& a) + { + printf ("Caught IV %d.\n", a.i); + } + } + + printf ("c == %d, d == %d\n", c, d); + return c != d || wrong; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/spec1.C b/gcc/testsuite/g++.old-deja/g++.eh/spec1.C new file mode 100644 index 000000000..0ff888369 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/spec1.C @@ -0,0 +1,39 @@ +// { dg-do run } +// Testing exception specifications. +// Test 1: the original exception succeeds. + +#include <stdlib.h> +#include <exception> + +void my_term () { exit (1); } +void my_unexp () { throw 42; } + +void +f () throw (char, int, std::bad_exception) +{ + throw 'a'; +} + +int main () +{ + std::set_terminate (my_term); + std::set_unexpected (my_unexp); + + try + { + f (); + } + catch (char) + { + return 0; + } + catch (int) + { + return 3; + } + catch (std::bad_exception) + { + return 4; + } + return 5; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/spec2.C b/gcc/testsuite/g++.old-deja/g++.eh/spec2.C new file mode 100644 index 000000000..5c7a91399 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/spec2.C @@ -0,0 +1,39 @@ +// { dg-do run } +// Testing exception specifications. +// Test 2: the second throw succeeds. + +#include <stdlib.h> +#include <exception> + +void my_term () { exit (1); } +void my_unexp () { throw 42; } + +void +f () throw (int, std::bad_exception) +{ + throw 'a'; +} + +int main () +{ + std::set_terminate (my_term); + std::set_unexpected (my_unexp); + + try + { + f (); + } + catch (char) + { + return 2; + } + catch (int) + { + return 0; + } + catch (std::bad_exception) + { + return 4; + } + return 5; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/spec3.C b/gcc/testsuite/g++.old-deja/g++.eh/spec3.C new file mode 100644 index 000000000..6239270ee --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/spec3.C @@ -0,0 +1,39 @@ +// { dg-do run } +// Testing exception specifications. +// Test 3: the bad_exception throw succeeds. + +#include <stdlib.h> +#include <exception> + +void my_term () { exit (1); } +void my_unexp () { throw 42; } + +void +f () throw (std::bad_exception) +{ + throw 'a'; +} + +int main () +{ + std::set_terminate (my_term); + std::set_unexpected (my_unexp); + + try + { + f (); + } + catch (char) + { + return 2; + } + catch (int) + { + return 3; + } + catch (std::bad_exception) + { + return 0; + } + return 5; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/spec4.C b/gcc/testsuite/g++.old-deja/g++.eh/spec4.C new file mode 100644 index 000000000..e1f702e20 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/spec4.C @@ -0,0 +1,39 @@ +// { dg-do run } +// Testing exception specifications. +// Test 4: all throws fail, call terminate. + +#include <stdlib.h> +#include <exception> + +void my_term () { exit (0); } +void my_unexp () { throw 42; } + +void +f () throw (short) +{ + throw 'a'; +} + +int main () +{ + std::set_terminate (my_term); + std::set_unexpected (my_unexp); + + try + { + f (); + } + catch (char) + { + return 2; + } + catch (int) + { + return 3; + } + catch (std::bad_exception) + { + return 4; + } + return 5; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/spec5.C b/gcc/testsuite/g++.old-deja/g++.eh/spec5.C new file mode 100644 index 000000000..107ba7f19 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/spec5.C @@ -0,0 +1,3 @@ +// { dg-do assemble } + +extern void *f(unsigned int k) throw(); diff --git a/gcc/testsuite/g++.old-deja/g++.eh/spec6.C b/gcc/testsuite/g++.old-deja/g++.eh/spec6.C new file mode 100644 index 000000000..015bbefdf --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/spec6.C @@ -0,0 +1,137 @@ +// { dg-do assemble } + +// Copyright (C) 1999 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 19 Jan 1999 <nathan@acm.org> + +// Determine that throw specifiers are checked correctly. + +// [except.spec] 1, a type in an exception specifier shall not be incomplete, +// or pointer or ref to incomplete +struct X; // { dg-error "" } forward declaration.* +void fn1() throw(X); // { dg-error "" } invalid use of undefined type +void fn2() throw(X *); // { dg-error "" } invalid use of undefined type +void fn3() throw(X &); // { dg-error "" } invalid use of undefined tyoe +void fn4() throw(void); // { dg-error "" } invalid use of void expression +void fn5() throw(void &); // { dg-error "" } invalid type // ERROR - invalid use of void +// except for cv pointer to void +void fn6() throw(void *); // ok -- pointer to void +void fn7() throw(void const *); // ok -- pointer to cv void + +template<class T> void fny() throw(T); // ok (so far) +template<> void fny<int>() throw(int); // ok +template<> void fny<void>() throw(void); // { dg-error "" } invalid use of void + +template<class T> void fnx(T *) throw(T){} // { dg-error "" } invalid use of void expression +void fx() +{ + fnx((int *)0); + fnx((void *)0); // { dg-message "instantiated from here" } +} + +// [except.spec] 2, exception specifiers must be the same set of types (but +// can be reordered) +void baz1() throw(int, char); +void baz1() throw(char, int){} // reordering is ok + +void baz2() throw(int, char); +void baz2() throw(int, char, int){} // duplicates are ignored + +typedef int Int; +void baz3() throw(int, char); +void baz3() throw(Int, char){} // typedefs are the same type ... + +void baz4() throw(int, Int, char); // ... so this is a duplicate +void baz4() throw(Int, char){} + +void fna() throw(int, char); // { dg-error "" } to previous declaration +void fna() throw(int const, char); // { dg-error "" } declaration different exceptions // ERROR - to previous declaration +void fna() throw(int){} // { dg-error "" } declaration different exceptions + +void fnb() throw(int, char); // { dg-error "" } to previous declaration +void fnb() throw(char){} // { dg-error "" } declaration different exceptions + +void fnc() throw(int, char); // { dg-error "" } to previous declaration +void fnc() throw(char, int, float){} // { dg-error "" } declaration different exceptions + +void fnd() throw(); // { dg-error "" } to previous declaration +void fnd() throw(char){} // { dg-error "" } declaration different exceptions + +void fne() throw(char); // { dg-error "" } to previous declaration +void fne() throw(){} // { dg-error "" } declaration different exceptions + +void fnf(); // { dg-error "" } to previous declaration +void fnf() throw(char){} // { dg-error "" } declaration different exceptions + +void fng() throw(char); // { dg-error "" } to previous declaration +void fng(){} // { dg-error "" } declaration different exceptions + +void fnh() throw(int, char); // { dg-error "" } to previous declaration +void fnh() throw(int, float){} // { dg-error "" } declaration different exceptions + +void fni() throw(int, char); // { dg-error "" } to previous declaration +void fni() throw(float, char){} // { dg-error "" } declaration different exceptions + +// [except.spec] 3, virtual function overriders shall throw a subset of the +// overridden function +struct E {}; +struct F : public E {}; +struct F1 : public E {}; +struct G : public F, F1 {}; +struct H : private E {}; +struct A +{ + virtual void foo() throw(); // { dg-error "" } overriding + virtual void baz() throw(double, int); + virtual void bar(); + virtual void qux() throw(E); + virtual void qux(int) throw(E const *); // { dg-error "" } overriding (pedantically) + virtual void quux() throw(F); // { dg-error "" } overriding + virtual void quux(int) throw(F *); // { dg-error "" } overriding + virtual void wibble() throw(E); // { dg-error "" } overriding + virtual void wobble() throw(E *); // { dg-error "" } overriding + virtual void wobble(int) throw(E *); // { dg-error "" } overriding + virtual void wabble(int) throw(E *); + virtual void wubble(int) throw(E *, H *); + virtual ~A() throw(); // { dg-error "" } overriding +}; + +struct B : A +{ + virtual void foo() throw(int); // { dg-error "" } looser throw - A::foo + virtual void baz() throw(double); // ok subset + virtual void bar(int) throw(int); // ok not overriding + virtual void qux() throw(F); // ok subset + virtual void qux(int) throw(F *); // { dg-error "" } looser (pedantically) + virtual void quux() throw(E); // { dg-error "" } looser throw - A::quux() + virtual void quux(int) throw(E *); // { dg-error "" } looser throw - A::quux(int) + virtual void wibble() throw(E *); // { dg-error "" } looser throw - A::wibble + virtual void wobble() throw(G *); // { dg-error "" } looser throw - A::wobble() + virtual void wobble(int) throw(H *); // { dg-error "" } looser throw - A::wobble(int) + virtual void wubble(int) throw(H *); // ok + virtual void wabble(int) throw(F1 *, F *); // ok +}; + +struct A1 +{ + virtual void foo() throw(int); + virtual void bar() throw(); // { dg-error "" } overriding + virtual ~A1() throw(int); +}; + +struct B1 : A +{ +}; + +struct C : A, A1 // { dg-error "" } looser throw - A::~A() +{ + virtual void foo() throw(int); // { dg-error "" } looser throw - A::foo + virtual void bar() throw(int); // { dg-error "" } looser throw - A1::bar +}; + +struct D : A, A1 +{ + virtual ~D() throw(int); // { dg-error "" } looser throw - A::~A() +}; + +// [except.spec] 5, types shall not be defined in exception specifiers +void fn8() throw(struct Z {}); // { dg-error "" } ANSI C++ forbids diff --git a/gcc/testsuite/g++.old-deja/g++.eh/spec7.C b/gcc/testsuite/g++.old-deja/g++.eh/spec7.C new file mode 100644 index 000000000..2ef88a249 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/spec7.C @@ -0,0 +1,20 @@ +// { dg-do run } +// Test that we allow simple throw specs on pointers. + +void f() throw () { } +void (*pf)() throw () = f; + +struct A +{ + void g() throw () { } + static void (A::*pmf)() throw (); +}; + +void (A::* A::pmf)() = &A::g; + +int main() +{ + pf (); + A a; + (a.*A::pmf)(); +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/terminate1.C b/gcc/testsuite/g++.old-deja/g++.eh/terminate1.C new file mode 100644 index 000000000..623fb8400 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/terminate1.C @@ -0,0 +1,27 @@ +// { dg-do run } +// Test that an exception thrown out of the constructor for the catch +// parameter (i.e. "after completing evaluation of the expression to be thrown +// but before the exception is caught") causes us to call terminate. + +#include <exception> +#include <cstdlib> + +void my_terminate () +{ + std::exit (0); +} + +struct A +{ + A () {} + A (const A&) { throw 1; } +}; + +int main (void) +{ + std::set_terminate (my_terminate); + + try { throw A(); } + catch (A) {} + return 1; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/terminate2.C b/gcc/testsuite/g++.old-deja/g++.eh/terminate2.C new file mode 100644 index 000000000..3a3115843 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/terminate2.C @@ -0,0 +1,17 @@ +// { dg-do run } +// Test that an unhandled exception causes us to call terminate. + +#include <exception> +#include <cstdlib> + +void my_terminate () +{ + std::exit (0); +} + +int main (void) +{ + std::set_terminate (my_terminate); + throw 1; + return 1; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/throw1.C b/gcc/testsuite/g++.old-deja/g++.eh/throw1.C new file mode 100644 index 000000000..e5d234be3 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/throw1.C @@ -0,0 +1,12 @@ +// { dg-do assemble } + +void athrow(const int & e) throw(int) +{ + throw e; +} + +int main(void) +{ + athrow(int()); + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/throw2.C b/gcc/testsuite/g++.old-deja/g++.eh/throw2.C new file mode 100644 index 000000000..63bb029d9 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/throw2.C @@ -0,0 +1,16 @@ +// { dg-do assemble } + +// Submitted by Sebastian Ritterbusch <uabp@rz.uni-karlsruhe.de> + +#define ANY int // a class with a public constructor + +void athrow(const ANY & e) throw(ANY) +{ + throw e; // { dg-bogus "" } discarding const +} + +int main(void) +{ + athrow(ANY()); + return 0; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/tmpl1.C b/gcc/testsuite/g++.old-deja/g++.eh/tmpl1.C new file mode 100644 index 000000000..985fcae6b --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/tmpl1.C @@ -0,0 +1,16 @@ +// { dg-do run } +template <class T> +void f() throw (T) +{ + throw 7; +} + + +int main() +{ + try { + f<int>(); + } catch (...) { + return 0; + } +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/tmpl2.C b/gcc/testsuite/g++.old-deja/g++.eh/tmpl2.C new file mode 100644 index 000000000..dd2801d26 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/tmpl2.C @@ -0,0 +1,32 @@ +// { dg-do assemble } +// { dg-options "-O" } + +// Posted by H. J. Lu <hjl@lucon.org> + +template<class T> +class FixSeq +{ +public: + void append(const T&); +}; +class foo +{ +public: + void setupIR(); +}; +typedef FixSeq<foo *> bar; +extern void dummy (foo *); +void * +foobar (bar &x, foo *p) +{ + try + { + p -> setupIR(); + } + catch(...) + { + dummy (p); + } + x.append(p); + return p; +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/tmpl3.C b/gcc/testsuite/g++.old-deja/g++.eh/tmpl3.C new file mode 100644 index 000000000..0ddf63c98 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/tmpl3.C @@ -0,0 +1,11 @@ +// { dg-do assemble } + +// Posted by Trevor Taylor <ttaylor@powerup.com.au> + +template<class T> struct A { + void X() throw(T); +}; + +template<class T> +inline void A<T>::X() +throw(T) { } diff --git a/gcc/testsuite/g++.old-deja/g++.eh/tmpl4.C b/gcc/testsuite/g++.old-deja/g++.eh/tmpl4.C new file mode 100644 index 000000000..14e455bb6 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/tmpl4.C @@ -0,0 +1,11 @@ +// { dg-do assemble } +// Origin: Mark Mitchell <mark@codesourcery.com> + +template <class T> void test(){ + try { + } + catch(int x){ + } +} + +template void test<int>(); diff --git a/gcc/testsuite/g++.old-deja/g++.eh/tmpl5.C b/gcc/testsuite/g++.old-deja/g++.eh/tmpl5.C new file mode 100644 index 000000000..4f9580bcb --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/tmpl5.C @@ -0,0 +1,13 @@ +// { dg-do assemble } +// Origin: Mark Mitchell <mark@codesourcery.com> + +template <class T = int> +struct S +{ + void f () + { + try { + } catch (int) { + } + } +}; diff --git a/gcc/testsuite/g++.old-deja/g++.eh/tmpl6.C b/gcc/testsuite/g++.old-deja/g++.eh/tmpl6.C new file mode 100644 index 000000000..d79e8ad29 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/tmpl6.C @@ -0,0 +1,18 @@ +// { dg-do assemble } +// Origin: Mark Mitchell <mark@codesourcery.com> + +struct S +{ + int i; +}; + +template <class T> +void f () +{ + try { + } catch (S& s) { + s.i = 3; + } +} + +template void f<int>(); diff --git a/gcc/testsuite/g++.old-deja/g++.eh/unwind1.C b/gcc/testsuite/g++.old-deja/g++.eh/unwind1.C new file mode 100644 index 000000000..076b550f4 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/unwind1.C @@ -0,0 +1,25 @@ +// { dg-do run } +// Test that unwinding properly restores SP. +// Contributed by Jason Merrill <jason@cygnus.com> + +void f (int i) +{ + throw i; +} + +int main () +{ + void *sp1 = __builtin_alloca (0); + + try + { + f (0); + } + catch (int) + { + } + + void *sp2 = __builtin_alloca (0); + + return (sp1 != sp2); +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/vbase1.C b/gcc/testsuite/g++.old-deja/g++.eh/vbase1.C new file mode 100644 index 000000000..96766d624 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/vbase1.C @@ -0,0 +1,25 @@ +// { dg-do run } +// Origin: Mark Mitchell <mark@codesourcery.com> + +int i; +int j; + +struct B +{ + B() { i = 1; } + ~B() { j = 7; } +}; + +struct D : virtual public B { + D () { throw 3; } +}; + +int main () +{ + try { + D d; + } catch (int) { + if (i != 1 || j != 7) + return 1; + } +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/vbase2.C b/gcc/testsuite/g++.old-deja/g++.eh/vbase2.C new file mode 100644 index 000000000..eaae9d93a --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/vbase2.C @@ -0,0 +1,35 @@ +// { dg-do run } +// Origin: Mark Mitchell <mark@codesourcery.com> + +int i; + +struct A +{ + A () { i++; } + ~A () { i--; } +}; + +struct B : public virtual A +{ + B () { throw 1; } +}; + +struct D: public B, virtual public A +{ +}; + +void f() +{ + D d; +} + +int main () +{ + try { + f(); + } catch (int) { + } + + return i; +} + diff --git a/gcc/testsuite/g++.old-deja/g++.eh/vbase3.C b/gcc/testsuite/g++.old-deja/g++.eh/vbase3.C new file mode 100644 index 000000000..f59b53b34 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/vbase3.C @@ -0,0 +1,13 @@ +// { dg-do assemble } +// Used to use -fsjlj-exceptions, but that isn't an option anymore. +// Origin: Donn Terry <donn@interix.com> + +struct ios { + virtual ~ios(); +}; +struct fstreambase : virtual public ios { + fstreambase(); +}; +fstreambase::fstreambase() +{ +} diff --git a/gcc/testsuite/g++.old-deja/g++.eh/vbase4.C b/gcc/testsuite/g++.old-deja/g++.eh/vbase4.C new file mode 100644 index 000000000..f151ed08d --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/vbase4.C @@ -0,0 +1,40 @@ +// { dg-do run } + +// Copyright (C) 2000 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 8 Mar 2000 <nathan@codesourcery.com> + +// Derived from PR#7 + +// We need to destroy the thrown object when exiting the catch +// clause. That needs to destroy the original thrown object, not +// the caught one (which might be a base). + +static int ok = 0; + +struct A +{ + A (){} + virtual ~A () {} +}; + +struct B : virtual A +{ + int value; + B () + :value(10) + {} + ~B() + { + if (value == 10) + ok = 1; + } +}; + +int main() +{ + try { + throw B (); + } catch (A & e) { + } + return !ok; +} |