[llvm-commits] CVS: llvm/test/Regression/C++Frontend/EH/exception_spec_test.cpp simple_rethrow.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Aug 28 14:59:01 PDT 2003
Changes in directory llvm/test/Regression/C++Frontend/EH:
exception_spec_test.cpp added (r1.1)
simple_rethrow.cpp added (r1.1)
---
Log message:
New testcases, all of which work with llvmg++!
This tests exception specifications, and also adds an "easy" rethrow test.
---
Diffs of the changes:
Index: llvm/test/Regression/C++Frontend/EH/exception_spec_test.cpp
diff -c /dev/null llvm/test/Regression/C++Frontend/EH/exception_spec_test.cpp:1.1
*** /dev/null Thu Aug 28 14:58:03 2003
--- llvm/test/Regression/C++Frontend/EH/exception_spec_test.cpp Thu Aug 28 14:57:53 2003
***************
*** 0 ****
--- 1,51 ----
+ // 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);
+ }
Index: llvm/test/Regression/C++Frontend/EH/simple_rethrow.cpp
diff -c /dev/null llvm/test/Regression/C++Frontend/EH/simple_rethrow.cpp:1.1
*** /dev/null Thu Aug 28 14:58:03 2003
--- llvm/test/Regression/C++Frontend/EH/simple_rethrow.cpp Thu Aug 28 14:57:53 2003
***************
*** 0 ****
--- 1,25 ----
+ #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;
+ }
More information about the llvm-commits
mailing list