[libcxx-commits] [libcxx] [libcxxabi] [libc++] [libc++abi] Initialize exception directly in make_exception_ptr if __cxa_init_primary_exception is available in ABI-library (PR #65534)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Dec 5 10:58:52 PST 2023
================
@@ -51,11 +71,25 @@ 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 _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION
+ 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>);
----------------
ldionne wrote:
```suggestion
void* __ex = exception_ptr::__init_native_exception(
sizeof(_Ep), const_cast<std::type_info*>(&typeid(_Ep)), [](void* __p) {
std::__destroy_at(static_cast<_Ep>(__p));
});
```
Then you don't need `__dest_thunk` at all.
https://github.com/llvm/llvm-project/pull/65534
More information about the libcxx-commits
mailing list