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