[libcxx-commits] [libcxxabi] [libc++] [libc++abi] Initialize exception directly in make_exception_ptr if __cxa_init_primary_exception is available in ABI-library (PR #65534)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Oct 26 03:55:42 PDT 2023
================
@@ -50,15 +67,38 @@ class _LIBCPP_EXPORTED_FROM_ABI exception_ptr {
template <class _Ep>
_LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
-# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+# if defined(_LIBCPP_EXCEPTION_PTR_DIRECT_INIT)
+ using _Ep2 = __decay_t<_Ep>;
+ void* __ex = exception_ptr::__init_native_exception(
+ sizeof(_Ep), const_cast<std::type_info*>(&typeid(_Ep)), exception_ptr::__dest_thunk<_Ep2>);
+ // This could happen with older versions of libcxxrt/libcxxabi,
+ // which don't yet support direct exception initialization.
+ if (__ex == nullptr) {
+ try {
+ throw __e;
+ } catch (...) {
+ return current_exception();
+ }
+ }
+
try {
- throw __e;
+ ::new (__ex) _Ep2(__e);
+ return exception_ptr::__from_native_exception_pointer(__ex);
} catch (...) {
+ exception_ptr::__free_native_exception(__ex);
return current_exception();
----------------
itrofimow wrote:
Yes, it would be the exception thrown by an `_Ep2` copy-ctor.
As far as i know the `std::make_exception_ptr` (and `throw` as well) behaves the same: https://godbolt.org/z/o981j9oxd
https://github.com/llvm/llvm-project/pull/65534
More information about the libcxx-commits
mailing list