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_;
AA20     explicit A(int id) : id_(id) {count++;}
AA21     A(const A& a) : id_(a.id_) {count++;}
~AA22     ~A() {count--;}
23 };
24 
25 int A::count = 0;
26 
f1()27 void f1()
28 {
29     throw A(3);
30 }
31 
f2()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 
main()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