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//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: no-exceptions
10
11#include <exception>
12#include <stdlib.h>
13#include <assert.h>
14
15struct B
16{
17 static int count;
18 int id_;
19 explicit B(int id) : id_(id) {count++;}
20 B(const B& a) : id_(a.id_) {count++;}
21 ~B() {count--;}
22};
23
24int B::count = 0;
25
26struct A
27 : B
28{
29 static int count;
30 int id_;
31 explicit A(int id) : B(id-1), id_(id) {count++;}
32 A(const A& a) : B(a.id_-1), id_(a.id_) {count++;}
33 ~A() {count--;}
34};
35
36int A::count = 0;
37
38void f1()
39{
40 assert(A::count == 0);
41 assert(B::count == 0);
42 A a(3);
43 assert(A::count == 1);
44 assert(B::count == 1);
45 throw a;
46 assert(false);
47}
48
49void f2()
50{
51 try
52 {
53 assert(A::count == 0);
54 f1();
55 assert(false);
56 }
57 catch (A a)
58 {
59 assert(A::count != 0);
60 assert(B::count != 0);
61 assert(a.id_ == 3);
62 throw;
63 }
64 catch (B b)
65 {
66 assert(false);
67 }
68}
69
70int main(int, char**)
71{
72 try
73 {
74 f2();
75 assert(false);
76 }
77 catch (const B& b)
78 {
79 assert(B::count != 0);
80 assert(b.id_ == 2);
81 }
82 assert(A::count == 0);
83 assert(B::count == 0);
84
85 return 0;
86}
87

source code of libcxxabi/test/catch_class_02.pass.cpp