blob: b07269061b4b244962dfdba91b546e8db8a2e911 [file] [log] [blame]
Howard Hinnanted2c2912010-05-27 17:06:52 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnanted2c2912010-05-27 17:06:52 +00007//
8//===----------------------------------------------------------------------===//
9
Howard Hinnanted2c2912010-05-27 17:06:52 +000010// <exception>
11
12// class nested_exception;
13
14// void rethrow_nested [[noreturn]] () const;
15
16#include <exception>
17#include <cstdlib>
18#include <cassert>
19
20class A
21{
22 int data_;
23public:
24 explicit A(int data) : data_(data) {}
25
26 friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}
27};
28
29void go_quietly()
30{
31 std::exit(0);
32}
33
34int main()
35{
36 {
37 try
38 {
39 throw A(2);
40 assert(false);
41 }
42 catch (const A&)
43 {
44 const std::nested_exception e;
45 assert(e.nested_ptr() != nullptr);
46 try
47 {
48 e.rethrow_nested();
49 assert(false);
50 }
51 catch (const A& a)
52 {
53 assert(a == A(2));
54 }
55 }
56 }
57 {
58 try
59 {
60 std::set_terminate(go_quietly);
61 const std::nested_exception e;
62 e.rethrow_nested();
63 assert(false);
64 }
65 catch (...)
66 {
67 assert(false);
68 }
69 }
70}