Add throw_exception_from_error overloads for boost::system::errc, std::errc

This commit is contained in:
Peter Dimov
2022-02-17 21:55:47 +02:00
parent d930cea481
commit 00c71cf388
2 changed files with 66 additions and 0 deletions

View File

@ -38,11 +38,21 @@ BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( error_code
boost::throw_with_location( system_error( e ), loc );
}
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( errc::errc_t const & e, boost::source_location const& loc )
{
boost::throw_with_location( system_error( make_error_code( e ) ), loc );
}
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( std::error_code const & e, boost::source_location const& loc )
{
boost::throw_with_location( std::system_error( e ), loc );
}
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( std::errc const & e, boost::source_location const& loc )
{
boost::throw_with_location( std::system_error( make_error_code( e ) ), loc );
}
#if defined(__GNUC__) && __GNUC__ >= 7 && __GNUC__ <= 8
# pragma GCC diagnostic pop
#endif

View File

@ -182,6 +182,34 @@ int main()
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<int, errc::errc_t> const r( in_place_error, errc::invalid_argument );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<int, std::errc> const r( std::errc::invalid_argument );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<X> r( 1 );
@ -374,5 +402,33 @@ int main()
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
{
result<void, errc::errc_t> const r( in_place_error, errc::invalid_argument );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
{
result<void, std::errc> const r( std::errc::invalid_argument );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
return boost::report_errors();
}