diff --git a/include/nlohmann/detail/macro_scope.hpp b/include/nlohmann/detail/macro_scope.hpp index f0f7dd571a..93d886f772 100644 --- a/include/nlohmann/detail/macro_scope.hpp +++ b/include/nlohmann/detail/macro_scope.hpp @@ -17,22 +17,6 @@ #include -NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ -template -[[noreturn]] inline void throw_if_exceptions_enabled(T&& exception) -{ -#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) || defined(EXCEPTIONS) - throw std::forward(exception); -#else - // Forward the exception (even if unused) and abort - std::forward(exception); - std::abort(); -#endif -} -} // namespace detail -NLOHMANN_JSON_NAMESPACE_END // exclude unsupported compilers #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) @@ -272,6 +256,16 @@ NLOHMANN_JSON_NAMESPACE_END e = ((it != std::end(m)) ? it : std::begin(m))->first; \ } +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ +template +[[noreturn]] inline void json_throw_from_serialize_macro(T&& exception) +{ + JSON_THROW(std::forward(exception)); +} +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END /*! @brief macro to briefly define a mapping between an enum and JSON @def NLOHMANN_JSON_SERIALIZE_ENUM_STRICT @@ -292,7 +286,7 @@ NLOHMANN_JSON_NAMESPACE_END }); \ if (it == std::end(m)) { \ auto value = static_cast::type>(e); \ - nlohmann::detail::throw_if_exceptions_enabled(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't serialize - enum value ", std::to_string(value), " out of range"), &j)); \ + nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't serialize - enum value ", std::to_string(value), " out of range"), &j)); \ } \ j = it->second; \ } \ @@ -309,7 +303,7 @@ NLOHMANN_JSON_NAMESPACE_END return ej_pair.second == j; \ }); \ if (it == std::end(m)) \ - nlohmann::detail::throw_if_exceptions_enabled(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't deserialize - invalid json value : ", j.dump()), &j)); \ + nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't deserialize - invalid json value : ", j.dump()), &j)); \ e = it->first; \ } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 8c7163aaf3..2c27de7099 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -2383,22 +2383,6 @@ JSON_HEDLEY_DIAGNOSTIC_POP // #include -NLOHMANN_JSON_NAMESPACE_BEGIN -namespace detail -{ -template -[[noreturn]] inline void throw_if_exceptions_enabled(T&& exception) -{ -#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) || defined(EXCEPTIONS) - throw std::forward(exception); -#else - // Forward the exception (even if unused) and abort - std::forward(exception); - std::abort(); -#endif -} -} // namespace detail -NLOHMANN_JSON_NAMESPACE_END // exclude unsupported compilers #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) @@ -2638,6 +2622,16 @@ NLOHMANN_JSON_NAMESPACE_END e = ((it != std::end(m)) ? it : std::begin(m))->first; \ } +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ +template +[[noreturn]] inline void json_throw_from_serialize_macro(T&& exception) +{ + JSON_THROW(std::forward(exception)); +} +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END /*! @brief macro to briefly define a mapping between an enum and JSON @def NLOHMANN_JSON_SERIALIZE_ENUM_STRICT @@ -2658,7 +2652,7 @@ NLOHMANN_JSON_NAMESPACE_END }); \ if (it == std::end(m)) { \ auto value = static_cast::type>(e); \ - nlohmann::detail::throw_if_exceptions_enabled(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't serialize - enum value ", std::to_string(value), " out of range"), &j)); \ + nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't serialize - enum value ", std::to_string(value), " out of range"), &j)); \ } \ j = it->second; \ } \ @@ -2675,7 +2669,7 @@ NLOHMANN_JSON_NAMESPACE_END return ej_pair.second == j; \ }); \ if (it == std::end(m)) \ - nlohmann::detail::throw_if_exceptions_enabled(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't deserialize - invalid json value : ", j.dump()), &j)); \ + nlohmann::detail::json_throw_from_serialize_macro(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't deserialize - invalid json value : ", j.dump()), &j)); \ e = it->first; \ }