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 #ifndef _LIBCPP___EXCEPTION_EXCEPTION_PTR_H
10 #define _LIBCPP___EXCEPTION_EXCEPTION_PTR_H
13 #include <__exception/operations.h>
14 #include <__memory/addressof.h>
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 # pragma GCC system_header
22 namespace std
{ // purposefully not using versioning namespace
24 #ifndef _LIBCPP_ABI_MICROSOFT
26 class _LIBCPP_EXPORTED_FROM_ABI exception_ptr
{
30 _LIBCPP_HIDE_FROM_ABI
exception_ptr() _NOEXCEPT
: __ptr_() {}
31 _LIBCPP_HIDE_FROM_ABI
exception_ptr(nullptr_t
) _NOEXCEPT
: __ptr_() {}
33 exception_ptr(const exception_ptr
&) _NOEXCEPT
;
34 exception_ptr
& operator=(const exception_ptr
&) _NOEXCEPT
;
35 ~exception_ptr() _NOEXCEPT
;
37 _LIBCPP_HIDE_FROM_ABI
explicit operator bool() const _NOEXCEPT
{ return __ptr_
!= nullptr; }
39 friend _LIBCPP_HIDE_FROM_ABI
bool operator==(const exception_ptr
& __x
, const exception_ptr
& __y
) _NOEXCEPT
{
40 return __x
.__ptr_
== __y
.__ptr_
;
43 friend _LIBCPP_HIDE_FROM_ABI
bool operator!=(const exception_ptr
& __x
, const exception_ptr
& __y
) _NOEXCEPT
{
47 friend _LIBCPP_EXPORTED_FROM_ABI exception_ptr
current_exception() _NOEXCEPT
;
48 friend _LIBCPP_EXPORTED_FROM_ABI
void rethrow_exception(exception_ptr
);
52 _LIBCPP_HIDE_FROM_ABI exception_ptr
make_exception_ptr(_Ep __e
) _NOEXCEPT
{
53 # ifndef _LIBCPP_HAS_NO_EXCEPTIONS
57 return current_exception();
65 #else // _LIBCPP_ABI_MICROSOFT
67 class _LIBCPP_EXPORTED_FROM_ABI exception_ptr
{
68 _LIBCPP_DIAGNOSTIC_PUSH
69 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field")
72 _LIBCPP_DIAGNOSTIC_POP
75 exception_ptr() _NOEXCEPT
;
76 exception_ptr(nullptr_t
) _NOEXCEPT
;
77 exception_ptr(const exception_ptr
& __other
) _NOEXCEPT
;
78 exception_ptr
& operator=(const exception_ptr
& __other
) _NOEXCEPT
;
79 exception_ptr
& operator=(nullptr_t
) _NOEXCEPT
;
80 ~exception_ptr() _NOEXCEPT
;
81 explicit operator bool() const _NOEXCEPT
;
84 _LIBCPP_EXPORTED_FROM_ABI
bool operator==(const exception_ptr
& __x
, const exception_ptr
& __y
) _NOEXCEPT
;
86 inline _LIBCPP_HIDE_FROM_ABI
bool operator!=(const exception_ptr
& __x
, const exception_ptr
& __y
) _NOEXCEPT
{
90 _LIBCPP_EXPORTED_FROM_ABI
void swap(exception_ptr
&, exception_ptr
&) _NOEXCEPT
;
92 _LIBCPP_EXPORTED_FROM_ABI exception_ptr
__copy_exception_ptr(void* __except
, const void* __ptr
);
93 _LIBCPP_EXPORTED_FROM_ABI exception_ptr
current_exception() _NOEXCEPT
;
94 _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI
void rethrow_exception(exception_ptr
);
96 // This is a built-in template function which automagically extracts the required
99 void* __GetExceptionInfo(_E
);
102 _LIBCPP_HIDE_FROM_ABI exception_ptr
make_exception_ptr(_Ep __e
) _NOEXCEPT
{
103 return __copy_exception_ptr(std::addressof(__e
), __GetExceptionInfo(__e
));
106 #endif // _LIBCPP_ABI_MICROSOFT
109 #endif // _LIBCPP___EXCEPTION_EXCEPTION_PTR_H