Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / language.support / support.exception / propagation / rethrow_exception.pass.cpp
blob57e1e8e90caa2ccdf4dd4348e385eec2b6a959bc
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 // UNSUPPORTED: no-exceptions
10 // <exception>
12 // void rethrow_exception [[noreturn]] (exception_ptr p);
14 #include <exception>
15 #include <cassert>
17 #include "test_macros.h"
19 struct A
21 static int constructed;
22 int data_;
24 A(int data = 0) : data_(data) {++constructed;}
25 ~A() {--constructed;}
26 A(const A& a) : data_(a.data_) {++constructed;}
29 int A::constructed = 0;
31 int main(int, char**)
34 std::exception_ptr p;
35 try
37 throw A(3);
39 catch (...)
41 p = std::current_exception();
43 try
45 std::rethrow_exception(p);
46 assert(false);
48 catch (const A& a)
50 #ifndef TEST_ABI_MICROSOFT
51 assert(A::constructed == 1);
52 #else
53 // On Windows the exception_ptr copies the exception
54 assert(A::constructed == 2);
55 #endif
56 assert(p != nullptr);
57 p = nullptr;
58 assert(p == nullptr);
59 assert(a.data_ == 3);
60 assert(A::constructed == 1);
62 assert(A::constructed == 0);
64 assert(A::constructed == 0);
66 return 0;