54 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// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION12// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS13 14// test uncaught_exception15 16#include <exception>17#include <cassert>18 19#include "test_macros.h"20 21struct A22{23 ~A()24 {25 assert(std::uncaught_exception());26 }27};28 29struct B30{31 B()32 {33 // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#47534 assert(!std::uncaught_exception());35 }36};37 38int main(int, char**)39{40 try41 {42 A a;43 assert(!std::uncaught_exception());44 throw B();45 }46 catch (...)47 {48 assert(!std::uncaught_exception());49 }50 assert(!std::uncaught_exception());51 52 return 0;53}54