'egcs_1_00_branch'.
From-SVN: r16658
--- /dev/null
+// 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); }
+
+main ()
+{
+ try {
+ A* ap = new (1, 5) A;
+ } catch (...) { }
+
+ return r;
+}
--- /dev/null
+// 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); }
+
+main ()
+{
+ try {
+ A* ap = new (1, 5) A;
+ } catch (...) { }
+
+ return r;
+}
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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;
+}
--- /dev/null
+#include <stdio.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;
+ }
+}
+
+main ()
+{
+ set_terminate (&eh_terminate);
+ eh_test (0);
+}
--- /dev/null
+// 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, bad_exception)
+{
+ throw 'a';
+}
+
+main ()
+{
+ set_terminate (my_term);
+ set_unexpected (my_unexp);
+
+ try
+ {
+ f ();
+ }
+ catch (char)
+ {
+ return 0;
+ }
+ catch (int)
+ {
+ return 3;
+ }
+ catch (bad_exception)
+ {
+ return 4;
+ }
+ return 5;
+}
--- /dev/null
+// 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, bad_exception)
+{
+ throw 'a';
+}
+
+main ()
+{
+ set_terminate (my_term);
+ set_unexpected (my_unexp);
+
+ try
+ {
+ f ();
+ }
+ catch (char)
+ {
+ return 2;
+ }
+ catch (int)
+ {
+ return 0;
+ }
+ catch (bad_exception)
+ {
+ return 4;
+ }
+ return 5;
+}
--- /dev/null
+// 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';
+}
+
+main ()
+{
+ set_terminate (my_term);
+ set_unexpected (my_unexp);
+
+ try
+ {
+ f ();
+ }
+ catch (char)
+ {
+ return 2;
+ }
+ catch (int)
+ {
+ return 3;
+ }
+ catch (bad_exception)
+ {
+ return 4;
+ }
+ return 5;
+}