+++ /dev/null
-#include <stdio.h>
-
-static int c;
-
-struct A {
- A() { ++c; }
- A(const A&) { ++c; }
- ~A() { --c; }
-};
-
-struct B {
- A a;
- B() { A a; throw 1; }
-};
-
-int main() {
- try {
- B b;
- } catch (...) {}
- if (!c) printf("All ok!\n");
- return c;
-}
-
+++ /dev/null
-// This testcase doesn't actually DO any EH
-#include <stdio.h>
-
-static void foo() {}
-int main() {
- try {
- foo();
- } catch(...) {
- return 1;
- }
- printf("All ok\n");
- return 0;
-}
+++ /dev/null
-// This tests that exception specifications interact properly with unexpected
-// handlers.
-
-#include <exception>
-#include <stdio.h>
-#include <stdlib.h>
-
-static void TerminateHandler() {
- printf("std::terminate called\n");
- exit(1);
-}
-
-static void UnexpectedHandler1() {
- printf("std::unexpected called: throwing a double\n");
- throw 1.0;
-}
-
-static void UnexpectedHandler2() {
- printf("std::unexpected called: throwing an int!\n");
- throw 1;
-}
-
-void test(bool Int) throw (double) {
- if (Int) {
- printf("Throwing an int from a function which only allows doubles!\n");
- throw 1;
- } else {
- printf("Throwing a double from a function which allows doubles!\n");
- throw 1.0;
- }
-}
-
-int main() {
- try {
- test(false);
- } catch (double D) {
- printf("Double successfully caught!\n");
- }
-
- std::set_terminate(TerminateHandler);
- std::set_unexpected(UnexpectedHandler1);
-
- try {
- test(true);
- } catch (double D) {
- printf("Double successfully caught!\n");
- }
-
- std::set_unexpected(UnexpectedHandler2);
- test(true);
-}
+++ /dev/null
-
-#include <stdio.h>
-
-static unsigned NumAs = 0;
-
-struct A {
- unsigned ANum;
- A() : ANum(NumAs++) { printf("Created A #%d\n", ANum); }
- A(const A &a) : ANum(NumAs++) { printf("Copy Created A #%d\n", ANum); }
- ~A() { printf("Destroyed A #%d\n", ANum); }
-};
-
-static bool ShouldThrow = false;
-
-int throws()
- try
-{
- if (ShouldThrow) throw 7; return 123;
-} catch (...) {
- printf("'throws' threw an exception: rethrowing!\n");
- throw;
-}
-
-struct B {
- A a0, a1, a2;
- int i;
- A a3, a4;
-
- B();
- ~B() { printf("B destructor!\n"); }
-};
-
-B::B()
-try
-: i(throws())
-{
- printf("In B constructor!\n");
-}
-catch (int i) {
- printf("In B catch block with int %d: auto rethrowing\n", i);
-}
-
-
-int main() {
- {
- B b; // Shouldn't throw.
- }
-
- try {
- ShouldThrow = true;
- B b;
- } catch (...) {
- printf("Caught exception!\n");
- }
-}
+++ /dev/null
-#include <stdio.h>
-
-int throws() {
- printf("Throwing int\n");
- throw 16;
-};
-
-int callsthrows() {
- try {
- throws();
- } catch (...) {
- printf("Caught something, rethrowing...\n");
- throw;
- }
-}
-
-int main() {
- try {
- callsthrows();
- } catch (int i) {
- printf("Caught int: %d\n", i);
- return i-16;
- }
- return 1;
-}
+++ /dev/null
-// Test throwing a constant int
-#include <stdio.h>
-
-static void foo() { throw 5; }
-int main() {
- try {
- foo();
- } catch (...) {
- printf("All ok\n");
- return 0;
- }
- return 1;
-}
+++ /dev/null
-// This tests hard situations for throwing, including the case where an
-// exception is active in more than one handler at a time (ie, it needs
-// refcounting)
-#include <cstdio>
-
-struct foo {
- int i;
- foo() : i(1) { }
- foo(const foo&) : i(2) {}
-};
-
-int callee(unsigned i) {
- if (i < 3) throw (int)i;
- if (i < 6) throw 1.0;
- if (i < 9) throw foo();
- return 0;
-}
-
-void rethrow() {
- throw;
-}
-
-int main() {
- for (unsigned i = 0; i < 10; ++i) {
- try {
- return callee(i);
- } catch (foo &F) {
- try {
- rethrow();
- } catch (foo &F) {
- std::printf("%d: 3\n", i);
- }
- } catch (int) {
- std::printf("%d: 1\n", i);
- } catch (...) {
- std::printf("%d: 2\n", i);
- }
- }
-}
-