Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:26

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