31#ifndef _EXCEPTION_PTR_H
32#define _EXCEPTION_PTR_H
40#if __cplusplus >= 201103L
44#if __cpp_lib_exception_ptr_cast >= 202603L
48#ifdef _GLIBCXX_EH_PTR_RELOPS_COMPAT
49# define _GLIBCXX_EH_PTR_USED __attribute__((__used__))
51# define _GLIBCXX_EH_PTR_USED
56namespace std _GLIBCXX_VISIBILITY(default)
65 namespace __exception_ptr
70 using __exception_ptr::exception_ptr;
81 template<typename _Ex>
83 _GLIBCXX_USE_NOEXCEPT;
88#if __cpp_lib_exception_ptr_cast >= 202603L
89 template<
typename _Ex>
90 constexpr optional<const _Ex&> exception_ptr_cast(
const exception_ptr&)
noexcept;
91 template<
typename _Ex>
95 namespace __exception_ptr
111 void* _M_exception_object;
113#if __cplusplus >= 202400L
114 [[__gnu__::__gnu_inline__]]
115 constexpr inline explicit exception_ptr(
void* __e) noexcept
116 : _M_exception_object(__e)
118 if (_M_exception_object)
120#if __cpp_if_consteval >= 202106L \
121 && _GLIBCXX_HAS_BUILTIN(__builtin_eh_ptr_adjust_ref)
123 __builtin_eh_ptr_adjust_ref(_M_exception_object, 1);
131 explicit exception_ptr(
void* __e) _GLIBCXX_USE_NOEXCEPT;
134 void _M_addref() _GLIBCXX_USE_NOEXCEPT;
135 void _M_release() _GLIBCXX_USE_NOEXCEPT;
137 void *_M_get()
const _GLIBCXX_NOEXCEPT __attribute__ ((__pure__));
141 template<
typename _Ex>
143 _GLIBCXX_USE_NOEXCEPT;
144#if __cpp_lib_exception_ptr_cast >= 202506L
145 template<
typename _Ex>
146 friend constexpr optional<const _Ex&>
147 std::exception_ptr_cast(
const exception_ptr&)
noexcept;
150 const void* _M_exception_ptr_cast(
const type_info&)
const
151 _GLIBCXX_USE_NOEXCEPT;
154 _GLIBCXX26_CONSTEXPR exception_ptr() _GLIBCXX_USE_NOEXCEPT;
156 _GLIBCXX26_CONSTEXPR exception_ptr(
const exception_ptr&)
157 _GLIBCXX_USE_NOEXCEPT;
159#if __cplusplus >= 201103L
160 _GLIBCXX26_CONSTEXPR exception_ptr(nullptr_t) noexcept
161 : _M_exception_object(
nullptr)
164 _GLIBCXX26_CONSTEXPR exception_ptr(exception_ptr&& __o) noexcept
165 : _M_exception_object(__o._M_exception_object)
166 { __o._M_exception_object =
nullptr; }
169#if (__cplusplus < 201103L) || defined (_GLIBCXX_EH_PTR_COMPAT)
170 typedef void (exception_ptr::*__safe_bool)();
173 exception_ptr(__safe_bool) _GLIBCXX_USE_NOEXCEPT;
176 _GLIBCXX26_CONSTEXPR exception_ptr&
177 operator=(
const exception_ptr&) _GLIBCXX_USE_NOEXCEPT;
179#if __cplusplus >= 201103L
180 _GLIBCXX26_CONSTEXPR exception_ptr&
181 operator=(exception_ptr&& __o)
noexcept
183 exception_ptr(
static_cast<exception_ptr&&
>(__o)).swap(*
this);
188 _GLIBCXX26_CONSTEXPR ~exception_ptr() _GLIBCXX_USE_NOEXCEPT;
190 _GLIBCXX26_CONSTEXPR
void
191 swap(exception_ptr&) _GLIBCXX_USE_NOEXCEPT;
193#ifdef _GLIBCXX_EH_PTR_COMPAT
195 void _M_safe_bool_dummy() _GLIBCXX_USE_NOEXCEPT;
196 bool operator!()
const _GLIBCXX_USE_NOEXCEPT
197 __attribute__ ((__pure__));
198 operator __safe_bool()
const _GLIBCXX_USE_NOEXCEPT;
201#if __cplusplus >= 201103L
202 _GLIBCXX26_CONSTEXPR
explicit operator bool()
const noexcept
203 {
return _M_exception_object; }
206#if __cpp_impl_three_way_comparison >= 201907L \
207 && ! defined _GLIBCXX_EH_PTR_RELOPS_COMPAT
208 _GLIBCXX26_CONSTEXPR
friend bool
209 operator==(
const exception_ptr&,
const exception_ptr&)
noexcept =
default;
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; }
216 friend _GLIBCXX_EH_PTR_USED
bool
217 operator!=(
const exception_ptr& __x,
const exception_ptr& __y)
218 _GLIBCXX_USE_NOEXCEPT
219 {
return __x._M_exception_object != __y._M_exception_object; }
223 friend _GLIBCXX26_CONSTEXPR
void
224 swap(exception_ptr& __lhs, exception_ptr& __rhs);
227 __cxa_exception_type()
const _GLIBCXX_USE_NOEXCEPT
228 __attribute__ ((__pure__));
232 _GLIBCXX26_CONSTEXPR
inline
233 exception_ptr::exception_ptr() _GLIBCXX_USE_NOEXCEPT
234 : _M_exception_object(0)
238 _GLIBCXX26_CONSTEXPR
inline
240 _GLIBCXX_USE_NOEXCEPT
241 : _M_exception_object(__other._M_exception_object)
243 if (_M_exception_object)
245#if __cpp_if_consteval >= 202106L \
246 && _GLIBCXX_HAS_BUILTIN(__builtin_eh_ptr_adjust_ref)
248 __builtin_eh_ptr_adjust_ref(_M_exception_object, 1);
257 _GLIBCXX26_CONSTEXPR
inline
258 exception_ptr::~exception_ptr() _GLIBCXX_USE_NOEXCEPT
260 if (_M_exception_object)
262#if __cpp_if_consteval >= 202106L \
263 && _GLIBCXX_HAS_BUILTIN(__builtin_eh_ptr_adjust_ref)
265 __builtin_eh_ptr_adjust_ref(_M_exception_object, -1);
274 _GLIBCXX26_CONSTEXPR
inline exception_ptr&
275 exception_ptr::operator=(
const exception_ptr& __other) _GLIBCXX_USE_NOEXCEPT
277 exception_ptr(__other).swap(*
this);
282 _GLIBCXX26_CONSTEXPR
inline void
283 exception_ptr::swap(exception_ptr &__other) _GLIBCXX_USE_NOEXCEPT
285 void *__tmp = _M_exception_object;
286 _M_exception_object = __other._M_exception_object;
287 __other._M_exception_object = __tmp;
291 _GLIBCXX26_CONSTEXPR
inline void
292 swap(exception_ptr& __lhs, exception_ptr& __rhs)
293 { __lhs.swap(__rhs); }
296 template<
typename _Ex>
297 _GLIBCXX_CDTOR_CALLABI
299 __dest_thunk(
void* __x)
300 {
static_cast<_Ex*
>(__x)->~_Ex(); }
305 using __exception_ptr::swap;
308 template<
typename _Ex>
309#if !(__cplusplus >= 201103L && __cpp_rtti) && !__cpp_exceptions
312 __attribute__ ((__always_inline__))
inline
317#if __cplusplus >= 201103L && __cpp_rtti
320#ifdef __glibcxx_constexpr_exceptions
324 using _Ex2 =
typename decay<_Ex>::type;
325 void* __e = __cxxabiv1::__cxa_allocate_exception(
sizeof(_Ex));
326 (void) __cxxabiv1::__cxa_init_primary_exception(
328 __exception_ptr::__dest_thunk<_Ex2>);
331 ::new (__e) _Ex2(__ex);
336 __cxxabiv1::__cxa_free_exception(__e);
342#ifdef __cpp_exceptions
349#if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_current_exception)
350 return __builtin_current_exception();
359#if __cpp_lib_exception_ptr_cast >= 202603L
360 template<
typename _Ex>
361 [[__gnu__::__always_inline__]]
362 constexpr optional<const _Ex&>
365 static_assert(!std::is_const_v<_Ex>);
366 static_assert(!std::is_reference_v<_Ex>);
367 static_assert(std::is_object_v<_Ex>);
368 static_assert(!std::is_array_v<_Ex>);
369 static_assert(!std::is_pointer_v<_Ex>);
370 static_assert(!std::is_member_pointer_v<_Ex>);
375 const type_info &__id =
typeid(
const _Ex&);
376 const _Ex* __exp =
static_cast<const _Ex*
>(__p._M_exception_ptr_cast(__id));
377 return optional<const _Ex&>::_S_from_ptr(__exp);
381#ifdef __cpp_exceptions
382 if (__p._M_exception_object)
387 catch (
const _Ex& __exc)
389 return optional<const _Ex&>(std::in_place, __exc);
400#undef _GLIBCXX_EH_PTR_USED
exception_ptr current_exception() noexcept
void rethrow_exception(exception_ptr)
Throw the object pointed to by the exception_ptr.
constexpr exception_ptr make_exception_ptr(_Ex) noexcept
Obtain an exception_ptr pointing to a copy of the supplied object.
ISO C++ entities toplevel namespace is std.
An opaque pointer to an arbitrary exception.
An opaque pointer to an arbitrary exception.