re PR libfortran/69799 (FAIL: gfortran.dg/coarray_allocate_3.f08 at -O1 and above)
[official-gcc.git] / libstdc++-v3 / testsuite / 18_support / exception_ptr / lifespan.cc
blobbf4f4ab5fa7676dc89f06a4be9f5441646a62745
1 // { dg-options "-std=gnu++11" }
2 // { dg-require-atomic-builtins "" }
4 // 2008-05-25 Sebastian Redl <sebastian.redl@getdesigned.at>
6 // Copyright (C) 2008-2016 Free Software Foundation, Inc.
7 //
8 // This file is part of the GNU ISO C++ Library. This library is free
9 // software; you can redistribute it and/or modify it under the
10 // terms of the GNU General Public License as published by the
11 // Free Software Foundation; either version 3, or (at your option)
12 // any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License along
20 // with this library; see the file COPYING3. If not see
21 // <http://www.gnu.org/licenses/>.
23 // Tests the life span of the exception object.
25 #include <exception>
26 #include <testsuite_hooks.h>
28 bool may_destruct = false;
30 class destructing
32 mutable bool copied;
34 public:
35 destructing() : copied(false) { }
36 destructing(const destructing &o) : copied(false) { o.copied = true; }
37 ~destructing() { VERIFY( copied || may_destruct ); }
40 void test01()
42 bool test __attribute__((unused)) = true;
43 using namespace std;
45 may_destruct = false;
47 // Test the destructing class.
49 destructing *d = new destructing;
50 destructing d2(*d);
51 delete d;
52 may_destruct = true;
54 may_destruct = false;
57 void test02()
59 bool test __attribute__((unused)) = true;
60 using namespace std;
62 may_destruct = false;
64 try {
65 throw destructing();
66 } catch(...) {
67 may_destruct = true;
69 may_destruct = false;
72 void test03()
74 bool test __attribute__((unused)) = true;
75 using namespace std;
77 may_destruct = false;
79 try {
80 throw destructing();
81 } catch(...) {
83 exception_ptr ep = current_exception();
85 may_destruct = true;
87 may_destruct = false;
90 void test04()
92 bool test __attribute__((unused)) = true;
93 using namespace std;
95 may_destruct = false;
98 exception_ptr ep;
99 try {
100 throw destructing();
101 } catch(...) {
102 ep = current_exception();
104 may_destruct = true;
106 may_destruct = false;
109 void test05_helper()
111 using namespace std;
112 try {
113 throw destructing();
114 } catch(...) {
115 exception_ptr ep = current_exception();
116 rethrow_exception(ep);
120 void test05()
122 bool test __attribute__((unused)) = true;
123 using namespace std;
125 may_destruct = false;
127 try {
128 test05_helper();
129 } catch(...) {
130 may_destruct = true;
132 may_destruct = false;
135 void test06_helper()
137 using namespace std;
138 try {
139 throw destructing();
140 } catch(...) {
141 exception_ptr ep = current_exception();
142 throw;
146 void test06()
148 bool test __attribute__((unused)) = true;
149 using namespace std;
151 may_destruct = false;
153 try
155 test06_helper();
157 catch(...)
159 may_destruct = true;
161 may_destruct = false;
164 std::exception_ptr gep;
166 void test99()
168 bool test __attribute__((unused)) = true;
169 using namespace std;
171 may_destruct = false;
173 try
175 throw destructing();
177 catch(...)
179 gep = current_exception();
183 int main()
185 test01();
186 test02();
187 test03();
188 test04();
189 test05();
190 test06();
192 test99();
193 may_destruct = true;
194 return 0;