forked from boostorg/system
Add throw_exception_from_error overload for std::exception_ptr
This commit is contained in:
@ -18,6 +18,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <system_error>
|
#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::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
|
#if defined(__GNUC__) && __GNUC__ >= 7 && __GNUC__ <= 8
|
||||||
# pragma GCC diagnostic pop
|
# pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
@ -32,6 +32,10 @@ BOOST_NORETURN void throw_exception_from_error( Y const &, boost::source_locatio
|
|||||||
throw E();
|
throw E();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct E2
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
@ -210,6 +214,34 @@ int main()
|
|||||||
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
|
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 );
|
result<X> r( 1 );
|
||||||
|
|
||||||
@ -430,5 +462,33 @@ int main()
|
|||||||
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
|
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();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user