[llvm-commits] CVS: llvm/test/Regression/C++Frontend/EH/function_try_block.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Aug 28 15:33:01 PDT 2003


Changes in directory llvm/test/Regression/C++Frontend/EH:

function_try_block.cpp added (r1.1)

---
Log message:

Add test for the last chapter of our C++ exception handling odyssey.  llvmg++
now fully supports all C++ exception handling functionality.


---
Diffs of the changes:

Index: llvm/test/Regression/C++Frontend/EH/function_try_block.cpp
diff -c /dev/null llvm/test/Regression/C++Frontend/EH/function_try_block.cpp:1.1
*** /dev/null	Thu Aug 28 15:32:46 2003
--- llvm/test/Regression/C++Frontend/EH/function_try_block.cpp	Thu Aug 28 15:32:36 2003
***************
*** 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");
+   }
+ }





More information about the llvm-commits mailing list