From b92be6417a3e58e5571bb59355390040ff51ad51 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 5 Feb 2022 05:24:29 +0200 Subject: [PATCH] Add a source_location parameter to throw_exception_from_error --- include/boost/system/result.hpp | 39 +++++++++++++++++---------------- test/result_value_access.cpp | 2 +- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/include/boost/system/result.hpp b/include/boost/system/result.hpp index aa581c2..225d985 100644 --- a/include/boost/system/result.hpp +++ b/include/boost/system/result.hpp @@ -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 #include #include +#include #include #include #include @@ -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 BOOST_CXX14_CONSTEXPR typename std::enable_if::value, T>::type - value() && + value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) && { - return std::move( value() ); + return std::move( value( loc ) ); } template BOOST_CXX14_CONSTEXPR typename std::enable_if::value, T&&>::type - value() && + value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) && { - return std::move( value() ); + return std::move( value( loc ) ); } template @@ -232,9 +233,9 @@ public: template BOOST_CXX14_CONSTEXPR typename std::enable_if::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 ); } } diff --git a/test/result_value_access.cpp b/test/result_value_access.cpp index 02eccb7..b8b00f4 100644 --- a/test/result_value_access.cpp +++ b/test/result_value_access.cpp @@ -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(); }