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: libcpp-no-exceptions
10 // XFAIL: libcpp-no-exceptions
11 
12 // XFAIL: macosx10.7
13 // XFAIL: macosx10.8
14 // XFAIL: macosx10.9
15 // XFAIL: macosx10.10
16 // XFAIL: macosx10.11
17 // XFAIL: with_system_cxx_lib=macosx10.12
18 // XFAIL: with_system_cxx_lib=macosx10.13
19 
20 // test uncaught_exceptions
21 
22 #include <exception>
23 #include <cassert>
24 
25 struct Uncaught {
26     Uncaught(int depth) : d_(depth) {}
27     ~Uncaught() { assert(std::uncaught_exceptions() == d_); }
28     int d_;
29     };
30 
31 struct Outer {
32     Outer(int depth) : d_(depth) {}
33     ~Outer() {
34     try {
35         assert(std::uncaught_exceptions() == d_);
36         Uncaught u(d_+1);
37         throw 2;
38     }
39     catch (int) {}
40     }
41     int d_;
42 };
43 
44 int main () {
45     assert(std::uncaught_exceptions() == 0);
46     {
47     Outer o(0);
48     }
49 
50     assert(std::uncaught_exceptions() == 0);
51     {
52     try {
53         Outer o(1);
54         throw 1;
55         }
56     catch (int) {
57         assert(std::uncaught_exceptions() == 0);
58         }
59     }
60     assert(std::uncaught_exceptions() == 0);
61 }
62