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 friend _GLIBCXX26_CONSTEXPR
void
219 swap(exception_ptr& __lhs, exception_ptr& __rhs);
222 __cxa_exception_type()
const _GLIBCXX_USE_NOEXCEPT
223 __attribute__ ((__pure__));
227 _GLIBCXX26_CONSTEXPR
inline
228 exception_ptr::exception_ptr() _GLIBCXX_USE_NOEXCEPT
229 : _M_exception_object(0)
233 _GLIBCXX26_CONSTEXPR
inline
235 _GLIBCXX_USE_NOEXCEPT
236 : _M_exception_object(__other._M_exception_object)
238 if (_M_exception_object)
240#if __cpp_if_consteval >= 202106L \
241 && _GLIBCXX_HAS_BUILTIN(__builtin_eh_ptr_adjust_ref)
243 __builtin_eh_ptr_adjust_ref(_M_exception_object, 1);
252 _GLIBCXX26_CONSTEXPR
inline
253 exception_ptr::~exception_ptr() _GLIBCXX_USE_NOEXCEPT
255 if (_M_exception_object)
257#if __cpp_if_consteval >= 202106L \
258 && _GLIBCXX_HAS_BUILTIN(__builtin_eh_ptr_adjust_ref)
260 __builtin_eh_ptr_adjust_ref(_M_exception_object, -1);
269 _GLIBCXX26_CONSTEXPR
inline exception_ptr&
270 exception_ptr::operator=(
const exception_ptr& __other) _GLIBCXX_USE_NOEXCEPT
272 exception_ptr(__other).swap(*
this);
277 _GLIBCXX26_CONSTEXPR
inline void
278 exception_ptr::swap(exception_ptr &__other) _GLIBCXX_USE_NOEXCEPT
280 void *__tmp = _M_exception_object;
281 _M_exception_object = __other._M_exception_object;
282 __other._M_exception_object = __tmp;
286 _GLIBCXX26_CONSTEXPR
inline void
287 swap(exception_ptr& __lhs, exception_ptr& __rhs)
288 { __lhs.swap(__rhs); }
291 template<
typename _Ex>
292 _GLIBCXX_CDTOR_CALLABI
294 __dest_thunk(
void* __x)
295 {
static_cast<_Ex*
>(__x)->~_Ex(); }
300 using __exception_ptr::swap;
303 template<
typename _Ex>
304#if !(__cplusplus >= 201103L && __cpp_rtti) && !__cpp_exceptions
307 __attribute__ ((__always_inline__))
inline
312#if __cplusplus >= 201103L && __cpp_rtti
315#ifdef __glibcxx_constexpr_exceptions
319 using _Ex2 =
typename decay<_Ex>::type;
320 void* __e = __cxxabiv1::__cxa_allocate_exception(
sizeof(_Ex));
321 (void) __cxxabiv1::__cxa_init_primary_exception(
323 __exception_ptr::__dest_thunk<_Ex2>);
326 ::new (__e) _Ex2(__ex);
331 __cxxabiv1::__cxa_free_exception(__e);
337#ifdef __cpp_exceptions
350#if __cpp_lib_exception_ptr_cast >= 202506L
351 template<
typename _Ex>
352 [[__gnu__::__always_inline__]]
356 static_assert(!std::is_const_v<_Ex>);
357 static_assert(!std::is_reference_v<_Ex>);
358 static_assert(std::is_object_v<_Ex>);
359 static_assert(!std::is_array_v<_Ex>);
360 static_assert(!std::is_pointer_v<_Ex>);
361 static_assert(!std::is_member_pointer_v<_Ex>);
366 const type_info &__id =
typeid(
const _Ex&);
367 return static_cast<const _Ex*
>(__p._M_exception_ptr_cast(__id));
371#ifdef __cpp_exceptions
372 if (__p._M_exception_object)
377 catch (
const _Ex& __exc)
390#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.