new
authorJason Merrill <jason@gcc.gnu.org>
Wed, 3 Dec 1997 20:29:19 +0000 (15:29 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 3 Dec 1997 20:29:19 +0000 (15:29 -0500)
From-SVN: r16930

gcc/testsuite/g++.old-deja/g++.eh/cleanup1.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.eh/new1.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.eh/new2.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.eh/ptr1.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.eh/rethrow4.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.eh/rethrow5.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.jason/destruct3.C
gcc/testsuite/g++.old-deja/g++.pt/enum2.C [new file with mode: 0644]

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 (file)
index 0000000..6faea26
--- /dev/null
@@ -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 (file)
index 0000000..3f7ebbc
--- /dev/null
@@ -0,0 +1,44 @@
+// Test that a throw in foo destroys the A, but does not free the memory.
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <new.h>
+
+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 (file)
index 0000000..6699f94
--- /dev/null
@@ -0,0 +1,44 @@
+// Test that a throw in B's constructor destroys the A and frees the memory.
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <new.h>
+
+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 (file)
index 0000000..2249526
--- /dev/null
@@ -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 (file)
index 0000000..c5dcd23
--- /dev/null
@@ -0,0 +1,45 @@
+// 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 (file)
index 0000000..f137d18
--- /dev/null
@@ -0,0 +1,44 @@
+// 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;
+}
index 94ca834d65f95dad789f26eb61c2e2079c681c48..d4bbf9ad79087bb4597b9f517cb18c4fe8b7577e 100644 (file)
@@ -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 (file)
index 0000000..5a2d7f3
--- /dev/null
@@ -0,0 +1,17 @@
+// Build don't link:
+
+struct U {
+  static int STATIC;
+};
+
+template <int* x> class FOO {
+public:
+  enum { n = 0 };
+};
+
+template <class A> class BAR {
+public:
+  enum { n = FOO<&A::STATIC>::n };
+};
+
+int n = BAR<U>::n;