mirror of
https://github.com/boostorg/system.git
synced 2025-07-30 04:27:14 +02:00
Add a source_location parameter to throw_exception_from_error
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
#ifndef BOOST_SYSTEM_RESULT_HPP_INCLUDED
|
#ifndef BOOST_SYSTEM_RESULT_HPP_INCLUDED
|
||||||
#define 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.
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
// https://www.boost.org/LICENSE_1_0.txt
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
@ -11,6 +11,7 @@
|
|||||||
#include <boost/system/detail/error_category_impl.hpp>
|
#include <boost/system/detail/error_category_impl.hpp>
|
||||||
#include <boost/variant2/variant.hpp>
|
#include <boost/variant2/variant.hpp>
|
||||||
#include <boost/throw_exception.hpp>
|
#include <boost/throw_exception.hpp>
|
||||||
|
#include <boost/assert/source_location.hpp>
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@ -32,14 +33,14 @@ namespace system
|
|||||||
# pragma GCC diagnostic ignored "-Wattributes"
|
# pragma GCC diagnostic ignored "-Wattributes"
|
||||||
#endif
|
#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
|
#if defined(__GNUC__) && __GNUC__ >= 7 && __GNUC__ <= 8
|
||||||
@ -170,7 +171,7 @@ public:
|
|||||||
// checked value access
|
// checked value access
|
||||||
#if defined( BOOST_NO_CXX11_REF_QUALIFIERS )
|
#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() )
|
if( has_value() )
|
||||||
{
|
{
|
||||||
@ -178,13 +179,13 @@ public:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw_exception_from_error( variant2::unsafe_get<1>( v_ ) );
|
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
BOOST_CXX14_CONSTEXPR T& value() &
|
BOOST_CXX14_CONSTEXPR T& value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) &
|
||||||
{
|
{
|
||||||
if( has_value() )
|
if( has_value() )
|
||||||
{
|
{
|
||||||
@ -192,11 +193,11 @@ public:
|
|||||||
}
|
}
|
||||||
else
|
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() )
|
if( has_value() )
|
||||||
{
|
{
|
||||||
@ -204,24 +205,24 @@ public:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw_exception_from_error( variant2::unsafe_get<1>( v_ ) );
|
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class U = T>
|
template<class U = T>
|
||||||
BOOST_CXX14_CONSTEXPR
|
BOOST_CXX14_CONSTEXPR
|
||||||
typename std::enable_if<std::is_move_constructible<U>::value, T>::type
|
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>
|
template<class U = T>
|
||||||
BOOST_CXX14_CONSTEXPR
|
BOOST_CXX14_CONSTEXPR
|
||||||
typename std::enable_if<!std::is_move_constructible<U>::value, T&&>::type
|
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>
|
template<class U = T>
|
||||||
@ -232,9 +233,9 @@ public:
|
|||||||
template<class U = T>
|
template<class U = T>
|
||||||
BOOST_CXX14_CONSTEXPR
|
BOOST_CXX14_CONSTEXPR
|
||||||
typename std::enable_if<!std::is_move_constructible<U>::value, T const&&>::type
|
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
|
#endif
|
||||||
@ -458,14 +459,14 @@ public:
|
|||||||
|
|
||||||
// checked value access
|
// 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() )
|
if( has_value() )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw_exception_from_error( variant2::unsafe_get<1>( v_ ) );
|
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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();
|
throw E();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user