Add a source_location parameter to throw_exception_from_error

This commit is contained in:
Peter Dimov
2022-02-05 05:24:29 +02:00
parent 245fff8af3
commit b92be6417a
2 changed files with 21 additions and 20 deletions

View File

@ -1,7 +1,7 @@
#ifndef BOOST_SYSTEM_RESULT_HPP_INCLUDED
#define BOOST_SYSTEM_RESULT_HPP_INCLUDED
// Copyright 2017, 2021 Peter Dimov.
// Copyright 2017, 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
@ -11,6 +11,7 @@
#include <boost/system/detail/error_category_impl.hpp>
#include <boost/variant2/variant.hpp>
#include <boost/throw_exception.hpp>
#include <boost/assert/source_location.hpp>
#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <type_traits>
@ -32,14 +33,14 @@ namespace system
# pragma GCC diagnostic ignored "-Wattributes"
#endif
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( error_code const & e )
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( error_code const & e, boost::source_location const& loc )
{
boost::throw_exception( system_error( e ) );
boost::throw_exception( system_error( e ), loc );
}
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( std::error_code const & e )
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( std::error_code const & e, boost::source_location const& loc )
{
boost::throw_exception( std::system_error( e ) );
boost::throw_exception( std::system_error( e ), loc );
}
#if defined(__GNUC__) && __GNUC__ >= 7 && __GNUC__ <= 8
@ -170,7 +171,7 @@ public:
// checked value access
#if defined( BOOST_NO_CXX11_REF_QUALIFIERS )
BOOST_CXX14_CONSTEXPR T value() const
BOOST_CXX14_CONSTEXPR T value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const
{
if( has_value() )
{
@ -178,13 +179,13 @@ public:
}
else
{
throw_exception_from_error( variant2::unsafe_get<1>( v_ ) );
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
}
}
#else
BOOST_CXX14_CONSTEXPR T& value() &
BOOST_CXX14_CONSTEXPR T& value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) &
{
if( has_value() )
{
@ -192,11 +193,11 @@ public:
}
else
{
throw_exception_from_error( variant2::unsafe_get<1>( v_ ) );
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
}
}
BOOST_CXX14_CONSTEXPR T const& value() const&
BOOST_CXX14_CONSTEXPR T const& value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const&
{
if( has_value() )
{
@ -204,24 +205,24 @@ public:
}
else
{
throw_exception_from_error( variant2::unsafe_get<1>( v_ ) );
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
}
}
template<class U = T>
BOOST_CXX14_CONSTEXPR
typename std::enable_if<std::is_move_constructible<U>::value, T>::type
value() &&
value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) &&
{
return std::move( value() );
return std::move( value( loc ) );
}
template<class U = T>
BOOST_CXX14_CONSTEXPR
typename std::enable_if<!std::is_move_constructible<U>::value, T&&>::type
value() &&
value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) &&
{
return std::move( value() );
return std::move( value( loc ) );
}
template<class U = T>
@ -232,9 +233,9 @@ public:
template<class U = T>
BOOST_CXX14_CONSTEXPR
typename std::enable_if<!std::is_move_constructible<U>::value, T const&&>::type
value() const &&
value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const &&
{
return std::move( value() );
return std::move( value( loc ) );
}
#endif
@ -458,14 +459,14 @@ public:
// checked value access
BOOST_CXX14_CONSTEXPR void value() const
BOOST_CXX14_CONSTEXPR void value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const
{
if( has_value() )
{
}
else
{
throw_exception_from_error( variant2::unsafe_get<1>( v_ ) );
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
}
}

View File

@ -27,7 +27,7 @@ struct E
{
};
BOOST_NORETURN void throw_exception_from_error( Y const & )
BOOST_NORETURN void throw_exception_from_error( Y const &, boost::source_location const& )
{
throw E();
}