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 // std::uncaught_exceptions() was introduced in the dylib on Mac OS 10.12
13 // XFAIL: with_system_cxx_lib=macosx10.11
14 // XFAIL: with_system_cxx_lib=macosx10.10
15 // XFAIL: with_system_cxx_lib=macosx10.9
16 // XFAIL: with_system_cxx_lib=macosx10.8
17 // XFAIL: with_system_cxx_lib=macosx10.7
18 
19 // However, std::uncaught_exceptions() gives the wrong answer in Mac OS 10.12
20 // and 10.13, where it only gives 0 or 1. This was fixed later.
21 // XFAIL: with_system_cxx_lib=macosx10.13
22 // XFAIL: with_system_cxx_lib=macosx10.12
23 
24 // test uncaught_exceptions
25 
26 #include <exception>
27 #include <cassert>
28 
29 #include "test_macros.h"
30 
31 struct Uncaught {
32     Uncaught(int depth) : d_(depth) {}
33     ~Uncaught() { assert(std::uncaught_exceptions() == d_); }
34     int d_;
35     };
36 
37 struct Outer {
38     Outer(int depth) : d_(depth) {}
39     ~Outer() {
40     try {
41         assert(std::uncaught_exceptions() == d_);
42         Uncaught u(d_+1);
43         throw 2;
44     }
45     catch (int) {}
46     }
47     int d_;
48 };
49 
50 int main(int, char**) {
51     assert(std::uncaught_exceptions() == 0);
52     {
53     Outer o(0);
54     }
55 
56     assert(std::uncaught_exceptions() == 0);
57     {
58     try {
59         Outer o(1);
60         throw 1;
61         }
62     catch (int) {
63         assert(std::uncaught_exceptions() == 0);
64         }
65     }
66     assert(std::uncaught_exceptions() == 0);
67 
68   return 0;
69 }
70