aboutsummaryrefslogtreecommitdiff
path: root/test/C++Frontend/EH/exception_spec_test.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-08-28 19:57:53 +0000
committerChris Lattner <sabre@nondot.org>2003-08-28 19:57:53 +0000
commit902d580bd9e594d1d8fe2df05513123ac0f0f45d (patch)
treecfb4f6584393e3510a859033bf5977cd8c1a29b7 /test/C++Frontend/EH/exception_spec_test.cpp
parent8df6bddd01355cdf3dcb26099f3a4eff5e9281bb (diff)
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
Diffstat (limited to 'test/C++Frontend/EH/exception_spec_test.cpp')
-rw-r--r--test/C++Frontend/EH/exception_spec_test.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/C++Frontend/EH/exception_spec_test.cpp b/test/C++Frontend/EH/exception_spec_test.cpp
new file mode 100644
index 0000000000..f80f0eeaab
--- /dev/null
+++ b/test/C++Frontend/EH/exception_spec_test.cpp
@@ -0,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);
+}