llvm.org GIT mirror llvm / 902d580
New testcases, all of which work with llvmg++! This tests exception specifications, and also adds an "easy" rethrow test. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8183 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 17 years ago
2 changed file(s) with 76 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 // This tests that exception specifications interact properly with unexpected
1 // handlers.
2
3 #include
4 #include
5 #include
6
7 static void TerminateHandler() {
8 printf("std::terminate called\n");
9 exit(1);
10 }
11
12 static void UnexpectedHandler1() {
13 printf("std::unexpected called: throwing a double\n");
14 throw 1.0;
15 }
16
17 static void UnexpectedHandler2() {
18 printf("std::unexpected called: throwing an int!\n");
19 throw 1;
20 }
21
22 void test(bool Int) throw (double) {
23 if (Int) {
24 printf("Throwing an int from a function which only allows doubles!\n");
25 throw 1;
26 } else {
27 printf("Throwing a double from a function which allows doubles!\n");
28 throw 1.0;
29 }
30 }
31
32 int main() {
33 try {
34 test(false);
35 } catch (double D) {
36 printf("Double successfully caught!\n");
37 }
38
39 std::set_terminate(TerminateHandler);
40 std::set_unexpected(UnexpectedHandler1);
41
42 try {
43 test(true);
44 } catch (double D) {
45 printf("Double successfully caught!\n");
46 }
47
48 std::set_unexpected(UnexpectedHandler2);
49 test(true);
50 }
0 #include
1
2 int throws() {
3 printf("Throwing int\n");
4 throw 16;
5 };
6
7 int callsthrows() {
8 try {
9 throws();
10 } catch (...) {
11 printf("Caught something, rethrowing...\n");
12 throw;
13 }
14 }
15
16 int main() {
17 try {
18 callsthrows();
19 } catch (int i) {
20 printf("Caught int: %d\n", i);
21 return i-16;
22 }
23 return 1;
24 }