From ca6d8cae45369624280a6c821e4a0c0090f4a480 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 3 Dec 1997 15:29:19 -0500 Subject: [PATCH] new From-SVN: r16930 --- gcc/testsuite/g++.old-deja/g++.eh/cleanup1.C | 34 ++++++++++++++ gcc/testsuite/g++.old-deja/g++.eh/new1.C | 44 ++++++++++++++++++ gcc/testsuite/g++.old-deja/g++.eh/new2.C | 44 ++++++++++++++++++ gcc/testsuite/g++.old-deja/g++.eh/ptr1.C | 22 +++++++++ gcc/testsuite/g++.old-deja/g++.eh/rethrow4.C | 45 +++++++++++++++++++ gcc/testsuite/g++.old-deja/g++.eh/rethrow5.C | 44 ++++++++++++++++++ .../g++.old-deja/g++.jason/destruct3.C | 5 ++- gcc/testsuite/g++.old-deja/g++.pt/enum2.C | 17 +++++++ 8 files changed, 253 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.old-deja/g++.eh/cleanup1.C create mode 100644 gcc/testsuite/g++.old-deja/g++.eh/new1.C create mode 100644 gcc/testsuite/g++.old-deja/g++.eh/new2.C create mode 100644 gcc/testsuite/g++.old-deja/g++.eh/ptr1.C create mode 100644 gcc/testsuite/g++.old-deja/g++.eh/rethrow4.C create mode 100644 gcc/testsuite/g++.old-deja/g++.eh/rethrow5.C create mode 100644 gcc/testsuite/g++.old-deja/g++.pt/enum2.C 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 00000000000..6faea269c9d --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/cleanup1.C @@ -0,0 +1,34 @@ +// 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/new1.C b/gcc/testsuite/g++.old-deja/g++.eh/new1.C new file mode 100644 index 00000000000..3f7ebbcba19 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/new1.C @@ -0,0 +1,44 @@ +// Test that a throw in foo destroys the A, but does not free the memory. + +#include +#include +#include + +struct A { + A(); + ~A(); +}; + +struct B { + B (A); +}; + +void foo (B*); + +int newed, created; + +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 *) malloc (size); +} + +void operator delete (void *p) throw () +{ + --newed; + 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 00000000000..6699f94aa9f --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/new2.C @@ -0,0 +1,44 @@ +// Test that a throw in B's constructor destroys the A and frees the memory. + +#include +#include +#include + +struct A { + A(); + ~A(); +}; + +struct B { + B (A); +}; + +void foo (B*); + +int newed, created; + +main () +{ + 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 *) malloc (size); +} + +void operator delete (void *p) throw () +{ + --newed; + free (p); +} 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 00000000000..224952655ba --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/ptr1.C @@ -0,0 +1,22 @@ +// 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%x\n", (long)e); + return !(long(e) != 5 && e->x == 5); + } + return 2; +} 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 00000000000..c5dcd2314a3 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/rethrow4.C @@ -0,0 +1,45 @@ +// Testcase for proper handling of rethrow. + +#include + +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 00000000000..f137d1841cd --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.eh/rethrow5.C @@ -0,0 +1,44 @@ +// Testcase for proper handling of rethrow. + +#include + +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++.jason/destruct3.C b/gcc/testsuite/g++.old-deja/g++.jason/destruct3.C index 94ca834d65f..d4bbf9ad790 100644 --- a/gcc/testsuite/g++.old-deja/g++.jason/destruct3.C +++ b/gcc/testsuite/g++.old-deja/g++.jason/destruct3.C @@ -1,3 +1,4 @@ +// Special g++ Options: -w // PRMS Id: 4342 (second testcase) // Bug: g++ still can't deal with ambiguous inheritance in destructor calls. // Build don't link: @@ -32,10 +33,10 @@ struct ccScreenObj : public ccScreenObjRep {}; struct ccVSTool : public ccImpExp, public ccUnwind -{}; // gets bogus error - XFAIL *-*-* +{}; struct ccSCCP : public ccVSTool -{}; // gets bogus error - XFAIL *-*-* +{}; void foo () { diff --git a/gcc/testsuite/g++.old-deja/g++.pt/enum2.C b/gcc/testsuite/g++.old-deja/g++.pt/enum2.C new file mode 100644 index 00000000000..5a2d7f32007 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.pt/enum2.C @@ -0,0 +1,17 @@ +// Build don't link: + +struct U { + static int STATIC; +}; + +template class FOO { +public: + enum { n = 0 }; +}; + +template class BAR { +public: + enum { n = FOO<&A::STATIC>::n }; +}; + +int n = BAR::n; -- 2.30.2