57 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: no-exceptions10 11// test uncaught_exceptions12 13#include <exception>14#include <cassert>15 16#include "test_macros.h"17 18struct Uncaught {19 Uncaught(int depth) : d_(depth) {}20 ~Uncaught() { assert(std::uncaught_exceptions() == d_); }21 int d_;22 };23 24struct Outer {25 Outer(int depth) : d_(depth) {}26 ~Outer() {27 try {28 assert(std::uncaught_exceptions() == d_);29 Uncaught u(d_+1);30 throw 2;31 }32 catch (int) {}33 }34 int d_;35};36 37int main(int, char**) {38 assert(std::uncaught_exceptions() == 0);39 {40 Outer o(0);41 }42 43 assert(std::uncaught_exceptions() == 0);44 {45 try {46 Outer o(1);47 throw 1;48 }49 catch (int) {50 assert(std::uncaught_exceptions() == 0);51 }52 }53 assert(std::uncaught_exceptions() == 0);54 55 return 0;56}57