31#ifndef _EXCEPTION_PTR_H
32#define _EXCEPTION_PTR_H
40#if __cplusplus >= 201103L
44#ifdef _GLIBCXX_EH_PTR_RELOPS_COMPAT
45# define _GLIBCXX_EH_PTR_USED __attribute__((__used__))
47# define _GLIBCXX_EH_PTR_USED
52namespace std _GLIBCXX_VISIBILITY(default)
61 namespace __exception_ptr
66 using __exception_ptr::exception_ptr;
77 template<typename _Ex>
79 _GLIBCXX_USE_NOEXCEPT;
84#if __cpp_lib_exception_ptr_cast >= 202506L
85 template<
typename _Ex>
86 constexpr const _Ex* exception_ptr_cast(
const exception_ptr&)
noexcept;
87 template<
typename _Ex>
91 namespace __exception_ptr
107 void* _M_exception_object;
109#if __cplusplus >= 202400L
110 constexpr explicit exception_ptr(
void* __e) noexcept
111 : _M_exception_object(__e)
113 if (_M_exception_object)
115#if __cpp_if_consteval >= 202106L \
116 && _GLIBCXX_HAS_BUILTIN(__builtin_eh_ptr_adjust_ref)
118 __builtin_eh_ptr_adjust_ref(_M_exception_object, 1);
126 explicit exception_ptr(
void* __e) _GLIBCXX_USE_NOEXCEPT;
129 void _M_addref() _GLIBCXX_USE_NOEXCEPT;
130 void _M_release() _GLIBCXX_USE_NOEXCEPT;
132 void *_M_get()
const _GLIBCXX_NOEXCEPT __attribute__ ((__pure__));
136 template<
typename _Ex>
138 _GLIBCXX_USE_NOEXCEPT;
139#if __cpp_lib_exception_ptr_cast >= 202506L
140 template<
typename _Ex>
141 friend constexpr const _Ex*
142 std::exception_ptr_cast(
const exception_ptr&)
noexcept;
145 const void* _M_exception_ptr_cast(
const type_info&)
const
146 _GLIBCXX_USE_NOEXCEPT;
149 _GLIBCXX26_CONSTEXPR exception_ptr() _GLIBCXX_USE_NOEXCEPT;
151 _GLIBCXX26_CONSTEXPR exception_ptr(
const exception_ptr&)
152 _GLIBCXX_USE_NOEXCEPT;
154#if __cplusplus >= 201103L
155 _GLIBCXX26_CONSTEXPR exception_ptr(nullptr_t) noexcept
156 : _M_exception_object(
nullptr)
159 _GLIBCXX26_CONSTEXPR exception_ptr(exception_ptr&& __o) noexcept
160 : _M_exception_object(__o._M_exception_object)
161 { __o._M_exception_object =
nullptr; }
164#if (__cplusplus < 201103L) || defined (_GLIBCXX_EH_PTR_COMPAT)
165 typedef void (exception_ptr::*__safe_bool)();
168 exception_ptr(__safe_bool) _GLIBCXX_USE_NOEXCEPT;
171 _GLIBCXX26_CONSTEXPR exception_ptr&
172 operator=(
const exception_ptr&) _GLIBCXX_USE_NOEXCEPT;
174#if __cplusplus >= 201103L
175 _GLIBCXX26_CONSTEXPR exception_ptr&
176 operator=(exception_ptr&& __o)
noexcept
178 exception_ptr(
static_cast<exception_ptr&&
>(__o)).swap(*
this);
183 _GLIBCXX26_CONSTEXPR ~exception_ptr() _GLIBCXX_USE_NOEXCEPT;
185 _GLIBCXX26_CONSTEXPR
void
186 swap(exception_ptr&) _GLIBCXX_USE_NOEXCEPT;
188#ifdef _GLIBCXX_EH_PTR_COMPAT
190 void _M_safe_bool_dummy() _GLIBCXX_USE_NOEXCEPT;
191 bool operator!()
const _GLIBCXX_USE_NOEXCEPT
192 __attribute__ ((__pure__));
193 operator __safe_bool()
const _GLIBCXX_USE_NOEXCEPT;
196#if __cplusplus >= 201103L
197 _GLIBCXX26_CONSTEXPR
explicit operator bool()
const noexcept
198 {
return _M_exception_object; }
201#if __cpp_impl_three_way_comparison >= 201907L \
202 && ! defined _GLIBCXX_EH_PTR_RELOPS_COMPAT
203 _GLIBCXX26_CONSTEXPR
friend bool
204 operator==(
const exception_ptr&,
const exception_ptr&)
noexcept =
default;
206 friend _GLIBCXX_EH_PTR_USED
bool
207 operator==(
const exception_ptr& __x,
const exception_ptr& __y)
208 _GLIBCXX_USE_NOEXCEPT
209 {
return __x._M_exception_object == __y._M_exception_object; }
211 friend _GLIBCXX_EH_PTR_USED
bool
212 operator!=(
const exception_ptr& __x,
const exception_ptr& __y)
213 _GLIBCXX_USE_NOEXCEPT
214 {
return __x._M_exception_object != __y._M_exception_object; }
218 __cxa_exception_type()
const _GLIBCXX_USE_NOEXCEPT
219 __attribute__ ((__pure__));
223 _GLIBCXX26_CONSTEXPR
inline
224 exception_ptr::exception_ptr() _GLIBCXX_USE_NOEXCEPT
225 : _M_exception_object(0)
229 _GLIBCXX26_CONSTEXPR
inline
231 _GLIBCXX_USE_NOEXCEPT
232 : _M_exception_object(__other._M_exception_object)
234 if (_M_exception_object)
236#if __cpp_if_consteval >= 202106L \
237 && _GLIBCXX_HAS_BUILTIN(__builtin_eh_ptr_adjust_ref)
239 __builtin_eh_ptr_adjust_ref(_M_exception_object, 1);
248 _GLIBCXX26_CONSTEXPR
inline
249 exception_ptr::~exception_ptr() _GLIBCXX_USE_NOEXCEPT
251 if (_M_exception_object)
253#if __cpp_if_consteval >= 202106L \
254 && _GLIBCXX_HAS_BUILTIN(__builtin_eh_ptr_adjust_ref)
256 __builtin_eh_ptr_adjust_ref(_M_exception_object, -1);
265 _GLIBCXX26_CONSTEXPR
inline exception_ptr&
266 exception_ptr::operator=(
const exception_ptr& __other) _GLIBCXX_USE_NOEXCEPT
268 exception_ptr(__other).swap(*
this);
273 _GLIBCXX26_CONSTEXPR
inline void
274 exception_ptr::swap(exception_ptr &__other) _GLIBCXX_USE_NOEXCEPT
276 void *__tmp = _M_exception_object;
277 _M_exception_object = __other._M_exception_object;
278 __other._M_exception_object = __tmp;
282 _GLIBCXX26_CONSTEXPR
inline void
283 swap(exception_ptr& __lhs, exception_ptr& __rhs)
284 { __lhs.swap(__rhs); }
287 template<
typename _Ex>
288 _GLIBCXX_CDTOR_CALLABI
290 __dest_thunk(
void* __x)
291 {
static_cast<_Ex*
>(__x)->~_Ex(); }
296 using __exception_ptr::swap;
299 template<
typename _Ex>
300#if !(__cplusplus >= 201103L && __cpp_rtti) && !__cpp_exceptions
303 __attribute__ ((__always_inline__))
inline
308#if __cplusplus >= 201103L && __cpp_rtti
311#ifdef __glibcxx_constexpr_exceptions
315 using _Ex2 =
typename decay<_Ex>::type;
316 void* __e = __cxxabiv1::__cxa_allocate_exception(
sizeof(_Ex));
317 (void) __cxxabiv1::__cxa_init_primary_exception(
319 __exception_ptr::__dest_thunk<_Ex2>);
322 ::new (__e) _Ex2(__ex);
327 __cxxabiv1::__cxa_free_exception(__e);
333#ifdef __cpp_exceptions
346#if __cpp_lib_exception_ptr_cast >= 202506L
347 template<
typename _Ex>
348 [[__gnu__::__always_inline__]]
352 static_assert(!std::is_const_v<_Ex>);
353 static_assert(!std::is_reference_v<_Ex>);
354 static_assert(std::is_object_v<_Ex>);
355 static_assert(!std::is_array_v<_Ex>);
356 static_assert(!std::is_pointer_v<_Ex>);
357 static_assert(!std::is_member_pointer_v<_Ex>);
362 const type_info &__id =
typeid(
const _Ex&);
363 return static_cast<const _Ex*
>(__p._M_exception_ptr_cast(__id));
367#ifdef __cpp_exceptions
368 if (__p._M_exception_object)
373 catch (
const _Ex& __exc)
386#undef _GLIBCXX_EH_PTR_USED
exception_ptr current_exception() noexcept
exception_ptr make_exception_ptr(_Ex) noexcept
Obtain an exception_ptr pointing to a copy of the supplied object.
void rethrow_exception(exception_ptr)
Throw the object pointed to by the exception_ptr.
ISO C++ entities toplevel namespace is std.
An opaque pointer to an arbitrary exception.
An opaque pointer to an arbitrary exception.