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 && target={{.+}}-apple-macosx10.{{9|10|11}}
13 
14 // However, std::uncaught_exceptions() gives the wrong answer in Mac OS 10.12
15 // and 10.13, where it only gives 0 or 1. This was fixed later.
16 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{12|13}}
17 
18 // test uncaught_exceptions
19 
20 #include <exception>
21 #include <cassert>
22 
23 #include "test_macros.h"
24 
25 struct Uncaught {
UncaughtUncaught26     Uncaught(int depth) : d_(depth) {}
~UncaughtUncaught27     ~Uncaught() { assert(std::uncaught_exceptions() == d_); }
28     int d_;
29     };
30 
31 struct Outer {
OuterOuter32     Outer(int depth) : d_(depth) {}
~OuterOuter33     ~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 
main(int,char **)44 int main(int, char**) {
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   return 0;
63 }
64