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 #include "test_macros.h"
26 
27 struct Uncaught {
28     Uncaught(int depth) : d_(depth) {}
29     ~Uncaught() { assert(std::uncaught_exceptions() == d_); }
30     int d_;
31     };
32 
33 struct Outer {
34     Outer(int depth) : d_(depth) {}
35     ~Outer() {
36     try {
37         assert(std::uncaught_exceptions() == d_);
38         Uncaught u(d_+1);
39         throw 2;
40     }
41     catch (int) {}
42     }
43     int d_;
44 };
45 
46 int main(int, char**) {
47     assert(std::uncaught_exceptions() == 0);
48     {
49     Outer o(0);
50     }
51 
52     assert(std::uncaught_exceptions() == 0);
53     {
54     try {
55         Outer o(1);
56         throw 1;
57         }
58     catch (int) {
59         assert(std::uncaught_exceptions() == 0);
60         }
61     }
62     assert(std::uncaught_exceptions() == 0);
63 
64   return 0;
65 }
66