]>
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 not_derived { virtual ~not_derived() noexcept; }; |
27 | inline not_derived::~not_derived() noexcept = default; | |
182da14a | 28 | |
95f2fd9c JW |
29 | struct uninheritable final { }; |
30 | ||
182da14a JW |
31 | void test01() |
32 | { | |
33 | bool test __attribute__((unused)) = false; | |
34 | ||
35 | try | |
36 | { | |
37 | std::throw_with_nested(derived()); | |
38 | } | |
39 | catch (const std::nested_exception& e) | |
40 | { | |
110a123a | 41 | VERIFY( e.nested_ptr() == 0 ); |
182da14a JW |
42 | try |
43 | { | |
44 | throw; | |
45 | } | |
46 | catch (const derived&) | |
47 | { | |
48 | test = true; | |
49 | } | |
50 | } | |
51 | VERIFY( test ); | |
52 | } | |
53 | ||
54 | void test02() | |
55 | { | |
56 | bool test __attribute__((unused)) = false; | |
57 | ||
58 | try | |
59 | { | |
60 | std::throw_with_nested(not_derived()); | |
61 | } | |
62 | catch (const std::nested_exception& e) | |
63 | { | |
110a123a | 64 | VERIFY( e.nested_ptr() == 0 ); |
182da14a JW |
65 | try |
66 | { | |
67 | throw; | |
68 | } | |
69 | catch (const not_derived&) | |
70 | { | |
71 | test = true; | |
72 | } | |
73 | } | |
74 | VERIFY( test ); | |
75 | } | |
76 | ||
95f2fd9c JW |
77 | void test03() |
78 | { | |
79 | bool test __attribute__((unused)) = false; | |
80 | ||
81 | try | |
82 | { | |
83 | std::throw_with_nested(uninheritable()); | |
84 | } | |
85 | catch (const std::nested_exception&) | |
86 | { | |
87 | VERIFY( false ); | |
88 | } | |
89 | catch(const uninheritable&) | |
90 | { | |
91 | test = true; | |
92 | } | |
93 | VERIFY( test ); | |
94 | } | |
95 | ||
182da14a JW |
96 | int main() |
97 | { | |
98 | test01(); | |
99 | test02(); | |
95f2fd9c | 100 | test03(); |
182da14a JW |
101 | return 0; |
102 | } |