diff --git a/include/boost/json/detail/value_to.hpp b/include/boost/json/detail/value_to.hpp index 0f95cdff0..fe3bba023 100644 --- a/include/boost/json/detail/value_to.hpp +++ b/include/boost/json/detail/value_to.hpp @@ -525,55 +525,6 @@ initialize_variant( V&& v, mp11::mp_int<1> ) } #endif // BOOST_NO_CXX17_HDR_VARIANT -struct locally_prohibit_exceptions -{}; - -template< class Ctx > -Ctx const& -make_locally_nonthrowing_context(Ctx const& ctx) noexcept -{ - return ctx; -} - -template< class... Ctxes > -std::tuple const& -make_locally_nonthrowing_context(std::tuple const& ctx) noexcept -{ - return ctx; -} - -template< class... Ctxes > -std::tuple -make_locally_nonthrowing_context(std::tuple const& ctx) - noexcept -{ - return std::tuple_cat(std::make_tuple( locally_prohibit_exceptions() ), ctx); -} - -template< class Ctx > -Ctx const& -remove_local_exception_prohibition(Ctx const& ctx) noexcept -{ - return ctx; -} - -template< class T, class... Ts, std::size_t... Is> -std::tuple -remove_local_exception_prohibition_helper( - std::tuple const& tup, - mp11::index_sequence) noexcept -{ - return std::tuple( std::get(tup)... ); -} - -template< class... Ctxes > -std::tuple -remove_local_exception_prohibition( - std::tuple const& ctx) noexcept -{ - return remove_local_exception_prohibition_helper( - ctx, mp11::index_sequence_for() ); -} template< class T, class Ctx > struct alternative_converter @@ -588,9 +539,8 @@ struct alternative_converter if( res ) return; - auto&& local_ctx = make_locally_nonthrowing_context(ctx); using V = mp11::mp_at; - auto attempt = try_value_to(jv, local_ctx); + auto attempt = try_value_to(jv, ctx); if( attempt ) { using cat = variant_construction_category; @@ -709,28 +659,6 @@ value_to_impl( return std::move(*res); } -template< class Ctx > -std::tuple -make_throwing_context(Ctx const& ctx) -{ - return std::tuple(allow_exceptions(), ctx); -} - -template< class... Ctxes > -std::tuple -make_throwing_context(std::tuple const& ctx) -{ - return std::tuple_cat(std::make_tuple( allow_exceptions() ), ctx); -} - -template< class... Ctxes > -std::tuple const& -make_throwing_context(std::tuple const& ctx) - noexcept -{ - return ctx; -} - template< class T, class Ctx, @@ -746,11 +674,7 @@ value_to_impl( value const& jv, Ctx const& ctx ) { - auto res = tag_invoke( - try_value_to_tag(), - jv, - Sup::get(ctx), - make_throwing_context(ctx)); + auto res = tag_invoke(try_value_to_tag(), jv, Sup::get(ctx), ctx); if( res.has_error() ) throw_system_error( res.error() ); return std::move(*res); @@ -809,36 +733,17 @@ value_to_impl( //---------------------------------------------------------- // User-provided conversions; nonthrowing -> throwing -template< class Ctx > -struct does_allow_exceptions : std::false_type -{ }; - -template< class... Ctxes > -struct does_allow_exceptions< std::tuple > - : std::true_type -{ }; - -template< class T, class... Args > -system::result -wrap_conversion_exceptions( std::true_type, value_to_tag, Args&& ... args ) -{ - return { - boost::system::in_place_value, - tag_invoke( value_to_tag(), static_cast(args)... )}; -} - template< class T, class... Args > system::result -wrap_conversion_exceptions( std::false_type, value_to_tag, Args&& ... args ) +wrap_conversion_exceptions( value_to_tag, Args&& ... args ) { #ifndef BOOST_NO_EXCEPTIONS try { #endif - return wrap_conversion_exceptions( - std::true_type(), - value_to_tag(), - static_cast(args)... ); + return { + boost::system::in_place_value, + tag_invoke( value_to_tag(), static_cast(args)... )}; #ifndef BOOST_NO_EXCEPTIONS } catch( std::bad_alloc const&) @@ -865,8 +770,7 @@ mp11::mp_if_c< value_to_impl( user_conversion_tag, try_value_to_tag, value const& jv, Ctx const& ) { - return wrap_conversion_exceptions( - does_allow_exceptions(), value_to_tag(), jv); + return wrap_conversion_exceptions(value_to_tag(), jv); } template< @@ -886,8 +790,7 @@ value_to_impl( value const& jv, Ctx const& ctx ) { - return wrap_conversion_exceptions( - does_allow_exceptions(), value_to_tag(), jv, Sup::get(ctx) ); + return wrap_conversion_exceptions( value_to_tag(), jv, Sup::get(ctx) ); } template< @@ -908,11 +811,7 @@ value_to_impl( Ctx const& ctx ) { return wrap_conversion_exceptions( - does_allow_exceptions(), - value_to_tag(), - jv, - Sup::get(ctx), - remove_local_exception_prohibition(ctx) ); + value_to_tag(), jv, Sup::get(ctx), ctx); } // no suitable conversion implementation @@ -930,8 +829,7 @@ template< class Impl, class T, class Ctx > T value_to_impl( Impl impl, value_to_tag, value const& jv, Ctx const& ctx ) { - return value_to_impl( - impl, try_value_to_tag(), jv, make_throwing_context(ctx) ).value(); + return value_to_impl(impl, try_value_to_tag(), jv, ctx).value(); } template< class Ctx, class T > diff --git a/include/boost/json/impl/conversion.hpp b/include/boost/json/impl/conversion.hpp index 738538e62..6c045ea01 100644 --- a/include/boost/json/impl/conversion.hpp +++ b/include/boost/json/impl/conversion.hpp @@ -387,9 +387,6 @@ struct conversion_category_impl< std::tuple, T, Dir > struct no_context {}; -struct allow_exceptions -{}; - template using can_convert = mp11::mp_not< std::is_same< diff --git a/test/value_to.cpp b/test/value_to.cpp index 8ba18ac60..854642178 100644 --- a/test/value_to.cpp +++ b/test/value_to.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #ifndef BOOST_NO_CXX17_HDR_VARIANT # include @@ -485,10 +484,9 @@ class value_to_test #endif // BOOST_NO_CXX17_HDR_OPTIONAL } - BOOST_TEST_THROWS( + BOOST_TEST_THROWS_WITH_LOCATION( value_to<::value_to_test_ns::T10>( - value{{"n", 0}, {"t3", "t10"}}, ctx... ), - std::invalid_argument); + value{{"n", 0}, {"t3", "t10"}}, ctx... )); #endif // BOOST_DESCRIBE_CXX14 }