1 //===----------------------------------------------------------------------===//
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
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.
13 // UNSUPPORTED: no-exceptions
16 // exception_ptr current_exception();
21 #include "test_macros.h"
25 static int constructed
;
29 A(const A
&) {++constructed
;}
32 int A::constructed
= 0;
37 std::exception_ptr p
= std::current_exception();
43 assert(A::constructed
== 0);
49 assert(A::constructed
== 1);
51 assert(A::constructed
== 0);
53 assert(A::constructed
== 0);
55 std::exception_ptr p2
;
58 assert(A::constructed
== 0);
64 std::exception_ptr p
= std::current_exception();
65 assert(A::constructed
== 1);
67 p2
= std::current_exception();
68 assert(A::constructed
== 1);
71 assert(A::constructed
== 1);
73 assert(A::constructed
== 0);
75 std::exception_ptr p2
;
78 assert(A::constructed
== 0);
84 std::exception_ptr p
= std::current_exception();
85 assert(A::constructed
== 1);
87 p2
= std::current_exception();
88 assert(A::constructed
== 1);
91 assert(A::constructed
== 1);
93 assert(A::constructed
== 0);
95 std::exception_ptr p2
;
98 assert(A::constructed
== 0);
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);
111 assert(A::constructed
== 1);
113 assert(A::constructed
== 0);
117 assert(A::constructed
== 0);
123 assert(A::constructed
== 1);
126 assert(A::constructed
== 1);
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);
148 assert(A::constructed
== 1);
151 std::exception_ptr p
= std::current_exception();
152 assert(A::constructed
== 1);
153 assert(p
!= nullptr);
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);
175 assert(A::constructed
== 1);
178 assert(A::constructed
== 1);
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);
202 assert(A::constructed
== 1);
205 assert(A::constructed
== 1);
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);
229 assert(A::constructed
== 1);
232 assert(A::constructed
== 1);
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);
257 assert(A::constructed
== 1);
260 assert(A::constructed
== 1);
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);