Don't double-rethrow std::exception_ptr (#53)

It's unnecessary to throw and then rethrow std::exception_ptr, just derive clone_base separately.

nb. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110835
This commit is contained in:
Ed Catmur
2023-08-04 20:28:03 -05:00
committed by GitHub
parent 03aa58e06e
commit ea70868a45

View File

@ -44,27 +44,48 @@ boost
exception_detail exception_detail
{ {
#ifndef BOOST_NO_CXX11_HDR_EXCEPTION #ifndef BOOST_NO_CXX11_HDR_EXCEPTION
struct class
std_exception_ptr_wrapper: BOOST_SYMBOL_VISIBLE
std::exception std_exception_ptr_clone_impl:
public virtual clone_base
{ {
std::exception_ptr p; std::exception_ptr p_;
explicit std_exception_ptr_wrapper( std::exception_ptr const & ptr ) BOOST_NOEXCEPT:
p(ptr) public:
explicit std_exception_ptr_clone_impl( std::exception_ptr const & ptr ) BOOST_NOEXCEPT:
p_(ptr)
{ {
} }
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
explicit std_exception_ptr_wrapper( std::exception_ptr && ptr ) BOOST_NOEXCEPT: ~std_exception_ptr_clone_impl() BOOST_NOEXCEPT_OR_NOTHROW
p(static_cast<std::exception_ptr &&>(ptr))
{ {
} }
#endif
private:
std_exception_ptr_clone_impl( std_exception_ptr_clone_impl const & x ):
p_(x.p_)
{
}
clone_base const*
clone() const
{
return new std_exception_ptr_clone_impl(*this);
}
void
rethrow() const
{
std::rethrow_exception(p_);
}
}; };
shared_ptr<exception_detail::clone_base const> shared_ptr<exception_detail::clone_base const>
inline inline
wrap_exception_ptr( std::exception_ptr const & e ) wrap_exception_ptr( std::exception_ptr const & e )
{ {
exception_detail::clone_base const & base = boost::enable_current_exception(std_exception_ptr_wrapper(e)); exception_detail::clone_base const & base = std_exception_ptr_clone_impl(e);
return shared_ptr<exception_detail::clone_base const>(base.clone()); return shared_ptr<exception_detail::clone_base const>(base.clone());
} }
#endif #endif
@ -536,20 +557,7 @@ boost
rethrow_exception_( exception_ptr const & p ) rethrow_exception_( exception_ptr const & p )
{ {
BOOST_ASSERT(p); BOOST_ASSERT(p);
#if defined( BOOST_NO_CXX11_HDR_EXCEPTION ) || defined( BOOST_NO_EXCEPTIONS )
p.ptr_->rethrow(); p.ptr_->rethrow();
#else
try
{
p.ptr_->rethrow();
}
catch(
std_exception_ptr_wrapper const & wrp)
{
// if an std::exception_ptr was wrapped above then rethrow it
std::rethrow_exception(wrp.p);
}
#endif
} }
} }