Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / language.support / support.exception / uncaught / uncaught_exceptions.pass.cpp
blob1d8b6b1560e88c951e667648ef2e843a7d37a652
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-exceptions
11 // std::uncaught_exceptions() was introduced in the dylib on Mac OS 10.12
12 // XFAIL: stdlib=apple-libc++ && target={{.+}}-apple-macosx10.{{9|10|11}}
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: stdlib=apple-libc++ && target={{.+}}-apple-macosx10.{{12|13}}
18 // test uncaught_exceptions
20 #include <exception>
21 #include <cassert>
23 #include "test_macros.h"
25 struct Uncaught {
26 Uncaught(int depth) : d_(depth) {}
27 ~Uncaught() { assert(std::uncaught_exceptions() == d_); }
28 int d_;
31 struct Outer {
32 Outer(int depth) : d_(depth) {}
33 ~Outer() {
34 try {
35 assert(std::uncaught_exceptions() == d_);
36 Uncaught u(d_+1);
37 throw 2;
39 catch (int) {}
41 int d_;
44 int main(int, char**) {
45 assert(std::uncaught_exceptions() == 0);
47 Outer o(0);
50 assert(std::uncaught_exceptions() == 0);
52 try {
53 Outer o(1);
54 throw 1;
56 catch (int) {
57 assert(std::uncaught_exceptions() == 0);
60 assert(std::uncaught_exceptions() == 0);
62 return 0;