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