Add throw_exception_from_error overload for std::exception_ptr

This commit is contained in:
Peter Dimov
2022-02-18 02:55:34 +02:00
parent 00c71cf388
commit 6d7a57a970
2 changed files with 73 additions and 0 deletions

View File

@ -18,6 +18,7 @@
#include <utility>
#include <iosfwd>
#include <system_error>
#include <exception>
//
@ -53,6 +54,18 @@ BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( std::errc
boost::throw_with_location( std::system_error( make_error_code( e ) ), loc );
}
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( std::exception_ptr const & p, boost::source_location const& loc )
{
if( p )
{
std::rethrow_exception( p );
}
else
{
boost::throw_with_location( std::bad_exception(), loc );
}
}
#if defined(__GNUC__) && __GNUC__ >= 7 && __GNUC__ <= 8
# pragma GCC diagnostic pop
#endif

View File

@ -32,6 +32,10 @@ BOOST_NORETURN void throw_exception_from_error( Y const &, boost::source_locatio
throw E();
}
struct E2
{
};
int main()
{
{
@ -210,6 +214,34 @@ int main()
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<int, std::exception_ptr> const r( std::make_exception_ptr( E2() ) );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), E2 );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<int, std::exception_ptr> const r( in_place_error );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::bad_exception );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<X> r( 1 );
@ -430,5 +462,33 @@ int main()
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
{
result<void, std::exception_ptr> const r( std::make_exception_ptr( E2() ) );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), E2 );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
{
result<void, std::exception_ptr> const r( in_place_error );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::bad_exception );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
return boost::report_errors();
}