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 [[__gnu__::__gnu_inline__]]
111 constexpr inline explicit exception_ptr(
void* __e) noexcept
112 : _M_exception_object(__e)
114 if (_M_exception_object)
116#if __cpp_if_consteval >= 202106L \
117 && _GLIBCXX_HAS_BUILTIN(__builtin_eh_ptr_adjust_ref)
119 __builtin_eh_ptr_adjust_ref(_M_exception_object, 1);
127 explicit exception_ptr(
void* __e) _GLIBCXX_USE_NOEXCEPT;
130 void _M_addref() _GLIBCXX_USE_NOEXCEPT;
131 void _M_release() _GLIBCXX_USE_NOEXCEPT;
133 void *_M_get()
const _GLIBCXX_NOEXCEPT __attribute__ ((__pure__));
137 template<
typename _Ex>
139 _GLIBCXX_USE_NOEXCEPT;
140#if __cpp_lib_exception_ptr_cast >= 202506L
141 template<
typename _Ex>
142 friend constexpr const _Ex*
143 std::exception_ptr_cast(
const exception_ptr&)
noexcept;
146 const void* _M_exception_ptr_cast(
const type_info&)
const
147 _GLIBCXX_USE_NOEXCEPT;
150 _GLIBCXX26_CONSTEXPR exception_ptr() _GLIBCXX_USE_NOEXCEPT;
152 _GLIBCXX26_CONSTEXPR exception_ptr(
const exception_ptr&)
153 _GLIBCXX_USE_NOEXCEPT;
155#if __cplusplus >= 201103L
156 _GLIBCXX26_CONSTEXPR exception_ptr(nullptr_t) noexcept
157 : _M_exception_object(
nullptr)
160 _GLIBCXX26_CONSTEXPR exception_ptr(exception_ptr&& __o) noexcept
161 : _M_exception_object(__o._M_exception_object)
162 { __o._M_exception_object =
nullptr; }
165#if (__cplusplus < 201103L) || defined (_GLIBCXX_EH_PTR_COMPAT)
166 typedef void (exception_ptr::*__safe_bool)();
169 exception_ptr(__safe_bool) _GLIBCXX_USE_NOEXCEPT;
172 _GLIBCXX26_CONSTEXPR exception_ptr&
173 operator=(
const exception_ptr&) _GLIBCXX_USE_NOEXCEPT;
175#if __cplusplus >= 201103L
176 _GLIBCXX26_CONSTEXPR exception_ptr&
177 operator=(exception_ptr&& __o)
noexcept
179 exception_ptr(
static_cast<exception_ptr&&
>(__o)).swap(*
this);
184 _GLIBCXX26_CONSTEXPR ~exception_ptr() _GLIBCXX_USE_NOEXCEPT;
186 _GLIBCXX26_CONSTEXPR
void
187 swap(exception_ptr&) _GLIBCXX_USE_NOEXCEPT;
189#ifdef _GLIBCXX_EH_PTR_COMPAT
191 void _M_safe_bool_dummy() _GLIBCXX_USE_NOEXCEPT;
192 bool operator!()
const _GLIBCXX_USE_NOEXCEPT
193 __attribute__ ((__pure__));
194 operator __safe_bool()
const _GLIBCXX_USE_NOEXCEPT;
197#if __cplusplus >= 201103L
198 _GLIBCXX26_CONSTEXPR
explicit operator bool()
const noexcept
199 {
return _M_exception_object; }
202#if __cpp_impl_three_way_comparison >= 201907L \
203 && ! defined _GLIBCXX_EH_PTR_RELOPS_COMPAT
204 _GLIBCXX26_CONSTEXPR
friend bool
205 operator==(
const exception_ptr&,
const exception_ptr&)
noexcept =
default;
207 friend _GLIBCXX_EH_PTR_USED
bool
208 operator==(
const exception_ptr& __x,
const exception_ptr& __y)
209 _GLIBCXX_USE_NOEXCEPT
210 {
return __x._M_exception_object == __y._M_exception_object; }
212 friend _GLIBCXX_EH_PTR_USED
bool
213 operator!=(
const exception_ptr& __x,
const exception_ptr& __y)
214 _GLIBCXX_USE_NOEXCEPT
215 {
return __x._M_exception_object != __y._M_exception_object; }
219 friend _GLIBCXX26_CONSTEXPR
void
220 swap(exception_ptr& __lhs, exception_ptr& __rhs);
223 __cxa_exception_type()
const _GLIBCXX_USE_NOEXCEPT
224 __attribute__ ((__pure__));
228 _GLIBCXX26_CONSTEXPR
inline
229 exception_ptr::exception_ptr() _GLIBCXX_USE_NOEXCEPT
230 : _M_exception_object(0)
234 _GLIBCXX26_CONSTEXPR
inline
236 _GLIBCXX_USE_NOEXCEPT
237 : _M_exception_object(__other._M_exception_object)
239 if (_M_exception_object)
241#if __cpp_if_consteval >= 202106L \
242 && _GLIBCXX_HAS_BUILTIN(__builtin_eh_ptr_adjust_ref)
244 __builtin_eh_ptr_adjust_ref(_M_exception_object, 1);
253 _GLIBCXX26_CONSTEXPR
inline
254 exception_ptr::~exception_ptr() _GLIBCXX_USE_NOEXCEPT
256 if (_M_exception_object)
258#if __cpp_if_consteval >= 202106L \
259 && _GLIBCXX_HAS_BUILTIN(__builtin_eh_ptr_adjust_ref)
261 __builtin_eh_ptr_adjust_ref(_M_exception_object, -1);
270 _GLIBCXX26_CONSTEXPR
inline exception_ptr&
271 exception_ptr::operator=(
const exception_ptr& __other) _GLIBCXX_USE_NOEXCEPT
273 exception_ptr(__other).swap(*
this);
278 _GLIBCXX26_CONSTEXPR
inline void
279 exception_ptr::swap(exception_ptr &__other) _GLIBCXX_USE_NOEXCEPT
281 void *__tmp = _M_exception_object;
282 _M_exception_object = __other._M_exception_object;
283 __other._M_exception_object = __tmp;
287 _GLIBCXX26_CONSTEXPR
inline void
288 swap(exception_ptr& __lhs, exception_ptr& __rhs)
289 { __lhs.swap(__rhs); }
292 template<
typename _Ex>
293 _GLIBCXX_CDTOR_CALLABI
295 __dest_thunk(
void* __x)
296 {
static_cast<_Ex*
>(__x)->~_Ex(); }
301 using __exception_ptr::swap;
304 template<
typename _Ex>
305#if !(__cplusplus >= 201103L && __cpp_rtti) && !__cpp_exceptions
308 __attribute__ ((__always_inline__))
inline
313#if __cplusplus >= 201103L && __cpp_rtti
316#ifdef __glibcxx_constexpr_exceptions
320 using _Ex2 =
typename decay<_Ex>::type;
321 void* __e = __cxxabiv1::__cxa_allocate_exception(
sizeof(_Ex));
322 (void) __cxxabiv1::__cxa_init_primary_exception(
324 __exception_ptr::__dest_thunk<_Ex2>);
327 ::new (__e) _Ex2(__ex);
332 __cxxabiv1::__cxa_free_exception(__e);
338#ifdef __cpp_exceptions
351#if __cpp_lib_exception_ptr_cast >= 202506L
352 template<
typename _Ex>
353 [[__gnu__::__always_inline__]]
357 static_assert(!std::is_const_v<_Ex>);
358 static_assert(!std::is_reference_v<_Ex>);
359 static_assert(std::is_object_v<_Ex>);
360 static_assert(!std::is_array_v<_Ex>);
361 static_assert(!std::is_pointer_v<_Ex>);
362 static_assert(!std::is_member_pointer_v<_Ex>);
367 const type_info &__id =
typeid(
const _Ex&);
368 return static_cast<const _Ex*
>(__p._M_exception_ptr_cast(__id));
372#ifdef __cpp_exceptions
373 if (__p._M_exception_object)
378 catch (
const _Ex& __exc)
391#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.