]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/18_support/exception_ptr/lifespan.cc
Re-instate last patch...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 18_support / exception_ptr / lifespan.cc
1 // { dg-options "-std=gnu++0x" }
2 // 2008-05-25 Sebastian Redl <sebastian.redl@getdesigned.at>
3
4 // Copyright (C) 2008 Free Software Foundation, Inc.
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 2, 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 COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
21
22 // Tests the life span of the exception object.
23
24 #include <exception>
25 #include <testsuite_hooks.h>
26
27 bool may_destruct = false;
28
29 class destructing
30 {
31 mutable bool copied;
32
33 public:
34 destructing() : copied(false) { }
35 destructing(const destructing &o) : copied(false) { o.copied = true; }
36 ~destructing() { VERIFY( copied || may_destruct ); }
37 };
38
39 void test01()
40 {
41 bool test __attribute__((unused)) = true;
42 using namespace std;
43
44 may_destruct = false;
45
46 // Test the destructing class.
47 {
48 destructing *d = new destructing;
49 destructing d2(*d);
50 delete d;
51 may_destruct = true;
52 }
53 may_destruct = false;
54 }
55
56 void test02()
57 {
58 bool test __attribute__((unused)) = true;
59 using namespace std;
60
61 may_destruct = false;
62
63 try {
64 throw destructing();
65 } catch(...) {
66 may_destruct = true;
67 }
68 may_destruct = false;
69 }
70
71 void test03()
72 {
73 bool test __attribute__((unused)) = true;
74 using namespace std;
75
76 may_destruct = false;
77
78 try {
79 throw destructing();
80 } catch(...) {
81 {
82 exception_ptr ep = current_exception();
83 }
84 may_destruct = true;
85 }
86 may_destruct = false;
87 }
88
89 void test04()
90 {
91 bool test __attribute__((unused)) = true;
92 using namespace std;
93
94 may_destruct = false;
95
96 {
97 exception_ptr ep;
98 try {
99 throw destructing();
100 } catch(...) {
101 ep = current_exception();
102 }
103 may_destruct = true;
104 }
105 may_destruct = false;
106 }
107
108 void test05_helper()
109 {
110 using namespace std;
111 try {
112 throw destructing();
113 } catch(...) {
114 exception_ptr ep = current_exception();
115 rethrow_exception(ep);
116 }
117 }
118
119 void test05()
120 {
121 bool test __attribute__((unused)) = true;
122 using namespace std;
123
124 may_destruct = false;
125
126 try {
127 test05_helper();
128 } catch(...) {
129 may_destruct = true;
130 }
131 may_destruct = false;
132 }
133
134 void test06_helper()
135 {
136 using namespace std;
137 try {
138 throw destructing();
139 } catch(...) {
140 exception_ptr ep = current_exception();
141 throw;
142 }
143 }
144
145 void test06()
146 {
147 bool test __attribute__((unused)) = true;
148 using namespace std;
149
150 may_destruct = false;
151
152 try {
153 test06_helper();
154 } catch(...) {
155 may_destruct = true;
156 }
157 may_destruct = false;
158 }
159
160 std::exception_ptr gep;
161
162 void test99()
163 {
164 bool test __attribute__((unused)) = true;
165 using namespace std;
166
167 may_destruct = false;
168
169 try {
170 throw destructing();
171 } catch(...) {
172 gep = current_exception();
173 }
174 }
175
176 int main()
177 {
178 test01();
179 test02();
180 test03();
181 test04();
182 test05();
183 test06();
184
185 test99();
186 may_destruct = true;
187 return 0;
188 }