Debian Codegraph @

libcxx/test/std/language.support/support.exception/except.nested/rethrow_nested.pass.cpp

raw
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 // <exception>
11
12 // class nested_exception;
13
14 // void rethrow_nested [[noreturn]] () const;
15
16 #include <exception>
17 #include <cstdlib>
18 #include <cassert>
19
20 #include "test_macros.h"
21
22 class A
23 {
24 int data_;
25 public:
26 explicit A(int data) : data_(data) {}
27
28 friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}
29 };
30
31 void go_quietly()
32 {
33 std::exit(0);
34 }
35
36 int main(int, char**)
37 {
38 {
39 try
40 {
41 throw A(2);
42 assert(false);
43 }
44 catch (const A&)
45 {
46 const std::nested_exception e;
47 assert(e.nested_ptr() != nullptr);
48 try
49 {
50 e.rethrow_nested();
51 assert(false);
52 }
53 catch (const A& a)
54 {
55 assert(a == A(2));
56 }
57 }
58 }
59 {
60 try
61 {
62 std::set_terminate(go_quietly);
63 const std::nested_exception e;
64 e.rethrow_nested();
65 assert(false);
66 }
67 catch (...)
68 {
69 assert(false);
70 }
71 }
72
73 return 0;
74 }