[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / libcxxabi / test / catch_class_01.pass.cpp
blob724dad3dcbdb4f17e9cabc2f8b40b9e66f7e2dab
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-exceptions
11 #include <exception>
12 #include <stdlib.h>
13 #include <assert.h>
15 struct A
17 static int count;
18 int id_;
19 explicit A(int id) : id_(id) {count++;}
20 A(const A& a) : id_(a.id_) {count++;}
21 ~A() {count--;}
24 int A::count = 0;
26 void f1()
28 throw A(3);
31 void f2()
33 try
35 assert(A::count == 0);
36 f1();
38 catch (A a)
40 assert(A::count != 0);
41 assert(a.id_ == 3);
42 throw;
46 int main(int, char**)
48 try
50 f2();
51 assert(false);
53 catch (const A& a)
55 assert(A::count != 0);
56 assert(a.id_ == 3);
58 assert(A::count == 0);
60 return 0;