File indexing completed on 2026-05-03 08:13:46
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___EXCEPTION_EXCEPTION_PTR_H
0010 #define _LIBCPP___EXCEPTION_EXCEPTION_PTR_H
0011
0012 #include <__config>
0013 #include <__cstddef/nullptr_t.h>
0014 #include <__exception/operations.h>
0015 #include <__memory/addressof.h>
0016 #include <__memory/construct_at.h>
0017 #include <__type_traits/decay.h>
0018 #include <cstdlib>
0019 #include <typeinfo>
0020
0021 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0022 # pragma GCC system_header
0023 #endif
0024
0025 #ifndef _LIBCPP_ABI_MICROSOFT
0026
0027 # if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION
0028
0029 namespace __cxxabiv1 {
0030
0031 extern "C" {
0032 _LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(size_t) throw();
0033 _LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_free_exception(void*) throw();
0034
0035 struct __cxa_exception;
0036 _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
0037 void*,
0038 std::type_info*,
0039 # if defined(_WIN32)
0040 void(__thiscall*)(void*)) throw();
0041 # elif defined(__wasm__)
0042
0043 void* (*)(void*)) throw();
0044 # else
0045 void (*)(void*)) throw();
0046 # endif
0047 }
0048
0049 }
0050
0051 # endif
0052
0053 #endif
0054
0055 namespace std {
0056
0057 #ifndef _LIBCPP_ABI_MICROSOFT
0058
0059 class _LIBCPP_EXPORTED_FROM_ABI exception_ptr {
0060 void* __ptr_;
0061
0062 static exception_ptr __from_native_exception_pointer(void*) _NOEXCEPT;
0063
0064 template <class _Ep>
0065 friend _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep) _NOEXCEPT;
0066
0067 public:
0068
0069 using __trivially_relocatable _LIBCPP_NODEBUG = exception_ptr;
0070
0071 _LIBCPP_HIDE_FROM_ABI exception_ptr() _NOEXCEPT : __ptr_() {}
0072 _LIBCPP_HIDE_FROM_ABI exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {}
0073
0074 exception_ptr(const exception_ptr&) _NOEXCEPT;
0075 exception_ptr& operator=(const exception_ptr&) _NOEXCEPT;
0076 ~exception_ptr() _NOEXCEPT;
0077
0078 _LIBCPP_HIDE_FROM_ABI explicit operator bool() const _NOEXCEPT { return __ptr_ != nullptr; }
0079
0080 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {
0081 return __x.__ptr_ == __y.__ptr_;
0082 }
0083
0084 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {
0085 return !(__x == __y);
0086 }
0087
0088 friend _LIBCPP_EXPORTED_FROM_ABI exception_ptr current_exception() _NOEXCEPT;
0089 friend _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr);
0090 };
0091
0092 template <class _Ep>
0093 _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
0094 # if _LIBCPP_HAS_EXCEPTIONS
0095 # if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION && __cplusplus >= 201103L
0096 using _Ep2 = __decay_t<_Ep>;
0097
0098 void* __ex = __cxxabiv1::__cxa_allocate_exception(sizeof(_Ep));
0099 # ifdef __wasm__
0100
0101 (void)__cxxabiv1::__cxa_init_primary_exception(
0102 __ex, const_cast<std::type_info*>(&typeid(_Ep)), [](void* __p) -> void* {
0103 # else
0104 (void)__cxxabiv1::__cxa_init_primary_exception(__ex, const_cast<std::type_info*>(&typeid(_Ep)), [](void* __p) {
0105 # endif
0106 std::__destroy_at(static_cast<_Ep2*>(__p));
0107 # ifdef __wasm__
0108 return __p;
0109 # endif
0110 });
0111
0112 try {
0113 ::new (__ex) _Ep2(__e);
0114 return exception_ptr::__from_native_exception_pointer(__ex);
0115 } catch (...) {
0116 __cxxabiv1::__cxa_free_exception(__ex);
0117 return current_exception();
0118 }
0119 # else
0120 try {
0121 throw __e;
0122 } catch (...) {
0123 return current_exception();
0124 }
0125 # endif
0126 # else
0127 ((void)__e);
0128 std::abort();
0129 # endif
0130 }
0131
0132 #else
0133
0134 class _LIBCPP_EXPORTED_FROM_ABI exception_ptr {
0135 _LIBCPP_DIAGNOSTIC_PUSH
0136 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field")
0137 void* __ptr1_;
0138 void* __ptr2_;
0139 _LIBCPP_DIAGNOSTIC_POP
0140
0141 public:
0142 exception_ptr() _NOEXCEPT;
0143 exception_ptr(nullptr_t) _NOEXCEPT;
0144 exception_ptr(const exception_ptr& __other) _NOEXCEPT;
0145 exception_ptr& operator=(const exception_ptr& __other) _NOEXCEPT;
0146 exception_ptr& operator=(nullptr_t) _NOEXCEPT;
0147 ~exception_ptr() _NOEXCEPT;
0148 explicit operator bool() const _NOEXCEPT;
0149 };
0150
0151 _LIBCPP_EXPORTED_FROM_ABI bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT;
0152
0153 inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {
0154 return !(__x == __y);
0155 }
0156
0157 _LIBCPP_EXPORTED_FROM_ABI void swap(exception_ptr&, exception_ptr&) _NOEXCEPT;
0158
0159 _LIBCPP_EXPORTED_FROM_ABI exception_ptr __copy_exception_ptr(void* __except, const void* __ptr);
0160 _LIBCPP_EXPORTED_FROM_ABI exception_ptr current_exception() _NOEXCEPT;
0161 [[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr);
0162
0163
0164
0165 template <class _E>
0166 void* __GetExceptionInfo(_E);
0167
0168 template <class _Ep>
0169 _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
0170 return __copy_exception_ptr(std::addressof(__e), __GetExceptionInfo(__e));
0171 }
0172
0173 #endif
0174 }
0175
0176 #endif