diff options
author | Chris Lattner <sabre@nondot.org> | 2003-08-28 20:32:36 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-08-28 20:32:36 +0000 |
commit | 206c7d029dd3444aa2fb3f4526e2fc729e6f5465 (patch) | |
tree | 8d0606506d8cd8660093b9b8e0a87c578809597d | |
parent | b40d5e7d940d469e2a5c984a390b10d65e67e689 (diff) | |
download | llvm-206c7d029dd3444aa2fb3f4526e2fc729e6f5465.tar.gz llvm-206c7d029dd3444aa2fb3f4526e2fc729e6f5465.tar.bz2 llvm-206c7d029dd3444aa2fb3f4526e2fc729e6f5465.tar.xz |
Add test for the last chapter of our C++ exception handling odyssey. llvmg++
now fully supports all C++ exception handling functionality.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8185 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | test/C++Frontend/EH/function_try_block.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/C++Frontend/EH/function_try_block.cpp b/test/C++Frontend/EH/function_try_block.cpp new file mode 100644 index 0000000000..001b7c50b8 --- /dev/null +++ b/test/C++Frontend/EH/function_try_block.cpp @@ -0,0 +1,55 @@ + +#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"); + } +} |