1 //===---------------------- catch_class_01.cpp ----------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: libcxxabi-no-exceptions 11 12 #include <exception> 13 #include <stdlib.h> 14 #include <assert.h> 15 16 struct A 17 { 18 static int count; 19 int id_; 20 explicit A(int id) : id_(id) {count++;} 21 A(const A& a) : id_(a.id_) {count++;} 22 ~A() {count--;} 23 }; 24 25 int A::count = 0; 26 27 void f1() 28 { 29 throw A(3); 30 } 31 32 void f2() 33 { 34 try 35 { 36 assert(A::count == 0); 37 f1(); 38 } 39 catch (A a) 40 { 41 assert(A::count != 0); 42 assert(a.id_ == 3); 43 throw; 44 } 45 } 46 47 int main() 48 { 49 try 50 { 51 f2(); 52 assert(false); 53 } 54 catch (const A& a) 55 { 56 assert(A::count != 0); 57 assert(a.id_ == 3); 58 } 59 assert(A::count == 0); 60 } 61