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() gives the wrong answer in versions of
12 // the dylib that don't contain 3a92ecc. Previously, it only returned
13 // 0 or 1.
14 // XFAIL: using-built-library-before-llvm-9
15 
16 // test uncaught_exceptions
17 
18 #include <exception>
19 #include <cassert>
20 
21 #include "test_macros.h"
22 
23 struct Uncaught {
UncaughtUncaught24     Uncaught(int depth) : d_(depth) {}
~UncaughtUncaught25     ~Uncaught() { assert(std::uncaught_exceptions() == d_); }
26     int d_;
27     };
28 
29 struct Outer {
OuterOuter30     Outer(int depth) : d_(depth) {}
~OuterOuter31     ~Outer() {
32     try {
33         assert(std::uncaught_exceptions() == d_);
34         Uncaught u(d_+1);
35         throw 2;
36     }
37     catch (int) {}
38     }
39     int d_;
40 };
41 
main(int,char **)42 int main(int, char**) {
43     assert(std::uncaught_exceptions() == 0);
44     {
45     Outer o(0);
46     }
47 
48     assert(std::uncaught_exceptions() == 0);
49     {
50     try {
51         Outer o(1);
52         throw 1;
53         }
54     catch (int) {
55         assert(std::uncaught_exceptions() == 0);
56         }
57     }
58     assert(std::uncaught_exceptions() == 0);
59 
60   return 0;
61 }
62