Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / language.support / support.exception / propagation / current_exception.pass.cpp
blob7624ea0195f9a4daf04eed879d46dddfc4cdb910
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // FIXME: This test needs to be rewritten for the MSVC exception_ptr semantics
10 // which copy the exception each time the exception_ptr is copied.
11 // XFAIL: msvc
13 // UNSUPPORTED: no-exceptions
14 // <exception>
16 // exception_ptr current_exception();
18 #include <exception>
19 #include <cassert>
21 #include "test_macros.h"
23 struct A
25 static int constructed;
27 A() {++constructed;}
28 ~A() {--constructed;}
29 A(const A&) {++constructed;}
32 int A::constructed = 0;
34 int main(int, char**)
37 std::exception_ptr p = std::current_exception();
38 assert(p == nullptr);
41 try
43 assert(A::constructed == 0);
44 throw A();
45 assert(false);
47 catch (...)
49 assert(A::constructed == 1);
51 assert(A::constructed == 0);
53 assert(A::constructed == 0);
55 std::exception_ptr p2;
56 try
58 assert(A::constructed == 0);
59 throw A();
60 assert(false);
62 catch (...)
64 std::exception_ptr p = std::current_exception();
65 assert(A::constructed == 1);
66 assert(p != nullptr);
67 p2 = std::current_exception();
68 assert(A::constructed == 1);
69 assert(p == p2);
71 assert(A::constructed == 1);
73 assert(A::constructed == 0);
75 std::exception_ptr p2;
76 try
78 assert(A::constructed == 0);
79 throw A();
80 assert(false);
82 catch (A&)
84 std::exception_ptr p = std::current_exception();
85 assert(A::constructed == 1);
86 assert(p != nullptr);
87 p2 = std::current_exception();
88 assert(A::constructed == 1);
89 assert(p == p2);
91 assert(A::constructed == 1);
93 assert(A::constructed == 0);
95 std::exception_ptr p2;
96 try
98 assert(A::constructed == 0);
99 throw A();
100 assert(false);
102 catch (A)
104 std::exception_ptr p = std::current_exception();
105 assert(A::constructed == 2);
106 assert(p != nullptr);
107 p2 = std::current_exception();
108 assert(A::constructed == 2);
109 assert(p == p2);
111 assert(A::constructed == 1);
113 assert(A::constructed == 0);
117 assert(A::constructed == 0);
118 throw A();
119 assert(false);
121 catch (...)
123 assert(A::constructed == 1);
126 assert(A::constructed == 1);
127 throw;
128 assert(false);
130 catch (...)
132 assert(A::constructed == 1);
134 assert(A::constructed == 1);
136 assert(A::constructed == 0);
138 assert(A::constructed == 0);
142 assert(A::constructed == 0);
143 throw A();
144 assert(false);
146 catch (...)
148 assert(A::constructed == 1);
151 std::exception_ptr p = std::current_exception();
152 assert(A::constructed == 1);
153 assert(p != nullptr);
154 throw;
155 assert(false);
157 catch (...)
159 assert(A::constructed == 1);
161 assert(A::constructed == 1);
163 assert(A::constructed == 0);
165 assert(A::constructed == 0);
169 assert(A::constructed == 0);
170 throw A();
171 assert(false);
173 catch (...)
175 assert(A::constructed == 1);
178 assert(A::constructed == 1);
179 throw;
180 assert(false);
182 catch (...)
184 std::exception_ptr p = std::current_exception();
185 assert(A::constructed == 1);
186 assert(p != nullptr);
188 assert(A::constructed == 1);
190 assert(A::constructed == 0);
192 assert(A::constructed == 0);
196 assert(A::constructed == 0);
197 throw A();
198 assert(false);
200 catch (...)
202 assert(A::constructed == 1);
205 assert(A::constructed == 1);
206 throw;
207 assert(false);
209 catch (...)
211 assert(A::constructed == 1);
213 std::exception_ptr p = std::current_exception();
214 assert(A::constructed == 1);
215 assert(p != nullptr);
217 assert(A::constructed == 0);
219 assert(A::constructed == 0);
223 assert(A::constructed == 0);
224 throw A();
225 assert(false);
227 catch (...)
229 assert(A::constructed == 1);
232 assert(A::constructed == 1);
233 throw;
234 assert(false);
236 catch (...)
238 assert(A::constructed == 1);
240 assert(A::constructed == 1);
242 std::exception_ptr p = std::current_exception();
243 assert(A::constructed == 0);
244 assert(p == nullptr);
246 assert(A::constructed == 0);
248 std::exception_ptr p;
251 assert(A::constructed == 0);
252 throw A();
253 assert(false);
255 catch (...)
257 assert(A::constructed == 1);
260 assert(A::constructed == 1);
261 throw;
262 assert(false);
264 catch (...)
266 p = std::current_exception();
267 assert(A::constructed == 1);
269 assert(A::constructed == 1);
271 assert(A::constructed == 1);
272 assert(p != nullptr);
274 assert(A::constructed == 0);
276 return 0;