2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
13 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCreate(void*);
14 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrDestroy(void*);
15 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCopy(void*, const void*);
16 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrAssign(void*, const void*);
17 _LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrCompare(const void*, const void*);
18 _LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrToBool(const void*);
19 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrSwap(void*, void*);
20 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCurrentException(void*);
21 [[noreturn]] _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrRethrow(const void*);
22 _LIBCPP_CRT_FUNC void __cdecl
23 __ExceptionPtrCopyException(void*, const void*, const void*);
27 exception_ptr::exception_ptr() noexcept { __ExceptionPtrCreate(this); }
28 exception_ptr::exception_ptr(nullptr_t) noexcept { __ExceptionPtrCreate(this); }
30 exception_ptr::exception_ptr(const exception_ptr& __other) noexcept {
31 __ExceptionPtrCopy(this, &__other);
33 exception_ptr& exception_ptr::operator=(const exception_ptr& __other) noexcept {
34 __ExceptionPtrAssign(this, &__other);
38 exception_ptr& exception_ptr::operator=(nullptr_t) noexcept {
40 __ExceptionPtrAssign(this, &dummy);
44 exception_ptr::~exception_ptr() noexcept { __ExceptionPtrDestroy(this); }
46 exception_ptr::operator bool() const noexcept {
47 return __ExceptionPtrToBool(this);
50 bool operator==(const exception_ptr& __x, const exception_ptr& __y) noexcept {
51 return __ExceptionPtrCompare(&__x, &__y);
55 void swap(exception_ptr& lhs, exception_ptr& rhs) noexcept {
56 __ExceptionPtrSwap(&rhs, &lhs);
59 exception_ptr __copy_exception_ptr(void* __except, const void* __ptr) {
60 exception_ptr __ret = nullptr;
62 __ExceptionPtrCopyException(&__ret, __except, __ptr);
66 exception_ptr current_exception() noexcept {
68 __ExceptionPtrCurrentException(&__ret);
73 void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); }
75 nested_exception::nested_exception() noexcept : __ptr_(current_exception()) {}
77 nested_exception::~nested_exception() noexcept {}
80 void nested_exception::rethrow_nested() const {
81 if (__ptr_ == nullptr)
83 rethrow_exception(__ptr_);