1*eb8650a7SLouis Dionne //===----------------------------------------------------------------------===//
2e434b34fSJonathan Roelofs //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e434b34fSJonathan Roelofs //
7e434b34fSJonathan Roelofs //===----------------------------------------------------------------------===//
8e434b34fSJonathan Roelofs 
98c61114cSLouis Dionne // UNSUPPORTED: no-exceptions
1057e446daSAsiri Rathnayake 
11e434b34fSJonathan Roelofs #include <exception>
12e434b34fSJonathan Roelofs #include <stdlib.h>
13e434b34fSJonathan Roelofs #include <assert.h>
14e434b34fSJonathan Roelofs 
15e434b34fSJonathan Roelofs struct A
16e434b34fSJonathan Roelofs {
17e434b34fSJonathan Roelofs     static int count;
18e434b34fSJonathan Roelofs     int id_;
AA19e434b34fSJonathan Roelofs     explicit A(int id) : id_(id) {count++;}
AA20e434b34fSJonathan Roelofs     A(const A& a) : id_(a.id_) {count++;}
~AA21e434b34fSJonathan Roelofs     ~A() {count--;}
22e434b34fSJonathan Roelofs };
23e434b34fSJonathan Roelofs 
24e434b34fSJonathan Roelofs int A::count = 0;
25e434b34fSJonathan Roelofs 
f1()26e434b34fSJonathan Roelofs void f1()
27e434b34fSJonathan Roelofs {
28e434b34fSJonathan Roelofs     throw A(3);
29e434b34fSJonathan Roelofs }
30e434b34fSJonathan Roelofs 
f2()31e434b34fSJonathan Roelofs void f2()
32e434b34fSJonathan Roelofs {
33e434b34fSJonathan Roelofs     try
34e434b34fSJonathan Roelofs     {
35e434b34fSJonathan Roelofs         assert(A::count == 0);
36e434b34fSJonathan Roelofs         f1();
37e434b34fSJonathan Roelofs     }
38e434b34fSJonathan Roelofs     catch (A a)
39e434b34fSJonathan Roelofs     {
40e434b34fSJonathan Roelofs         assert(A::count != 0);
41e434b34fSJonathan Roelofs         assert(a.id_ == 3);
42e434b34fSJonathan Roelofs         throw;
43e434b34fSJonathan Roelofs     }
44e434b34fSJonathan Roelofs }
45e434b34fSJonathan Roelofs 
main(int,char **)46504bc07dSLouis Dionne int main(int, char**)
47e434b34fSJonathan Roelofs {
48e434b34fSJonathan Roelofs     try
49e434b34fSJonathan Roelofs     {
50e434b34fSJonathan Roelofs         f2();
51e434b34fSJonathan Roelofs         assert(false);
52e434b34fSJonathan Roelofs     }
53e434b34fSJonathan Roelofs     catch (const A& a)
54e434b34fSJonathan Roelofs     {
55e434b34fSJonathan Roelofs         assert(A::count != 0);
56e434b34fSJonathan Roelofs         assert(a.id_ == 3);
57e434b34fSJonathan Roelofs     }
58e434b34fSJonathan Roelofs     assert(A::count == 0);
59504bc07dSLouis Dionne 
60504bc07dSLouis Dionne     return 0;
61e434b34fSJonathan Roelofs }
62