]>
Commit | Line | Data |
---|---|---|
52066eae | 1 | // { dg-do run { target c++11 } } |
182da14a JW |
2 | // { dg-require-atomic-builtins "" } |
3 | ||
818ab71a | 4 | // Copyright (C) 2009-2016 Free Software Foundation, Inc. |
182da14a JW |
5 | // |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 3, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING3. If not see | |
19 | // <http://www.gnu.org/licenses/>. | |
20 | ||
21 | #include <exception> | |
22 | #include <testsuite_hooks.h> | |
23 | ||
24 | struct derived : std::nested_exception { }; | |
25 | ||
8535715d PC |
26 | struct base { virtual ~base() noexcept; }; |
27 | inline base::~base() noexcept = default; | |
182da14a JW |
28 | |
29 | struct derived2 : base, std::nested_exception { }; | |
30 | ||
31 | void test01() | |
32 | { | |
33 | bool test __attribute__((unused)) = false; | |
34 | ||
35 | try | |
36 | { | |
37 | throw 42; | |
38 | } | |
39 | catch (...) | |
40 | { | |
41 | derived d; | |
42 | try | |
43 | { | |
44 | std::rethrow_if_nested(d); | |
45 | } | |
46 | catch (const int& i) | |
47 | { | |
48 | test = true; | |
49 | VERIFY( i == 42 ); | |
50 | } | |
51 | } | |
52 | ||
53 | VERIFY( test ); | |
54 | } | |
55 | ||
56 | void test02() | |
57 | { | |
58 | bool test __attribute__((unused)) = false; | |
59 | ||
60 | try | |
61 | { | |
62 | throw base(); | |
63 | } | |
64 | catch (const base& b) | |
65 | { | |
66 | std::rethrow_if_nested(b); | |
67 | test = true; | |
68 | } | |
69 | ||
70 | VERIFY( test ); | |
71 | } | |
72 | ||
73 | void test03() | |
74 | { | |
75 | bool test __attribute__((unused)) = false; | |
76 | ||
77 | try | |
78 | { | |
79 | throw 42; | |
80 | } | |
81 | catch (...) | |
82 | { | |
83 | try | |
84 | { | |
85 | throw derived2(); | |
86 | } | |
87 | catch (const base& b) | |
88 | { | |
89 | try | |
90 | { | |
91 | std::rethrow_if_nested(b); | |
92 | } | |
93 | catch (const int& i) | |
94 | { | |
95 | VERIFY( i == 42 ); | |
96 | test = true; | |
97 | } | |
98 | } | |
99 | } | |
100 | ||
101 | VERIFY( test ); | |
102 | } | |
103 | ||
104 | ||
105 | int main() | |
106 | { | |
107 | test01(); | |
108 | test02(); | |
109 | test03(); | |
110 | return 0; | |
111 | } |