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 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION
12 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
13 
14 // test uncaught_exception
15 
16 #include <exception>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 
21 struct A
22 {
23     ~A()
24     {
25         assert(std::uncaught_exception());
26     }
27 };
28 
29 struct B
30 {
31     B()
32     {
33         // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#475
34         assert(!std::uncaught_exception());
35     }
36 };
37 
38 int main(int, char**)
39 {
40     try
41     {
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