diff --git a/docs/mkdocs/docs/examples/nlohmann_json_deserialize_enum_strict.cpp b/docs/mkdocs/docs/examples/nlohmann_json_deserialize_enum_strict.cpp index 6675386d78..bd93cf412d 100644 --- a/docs/mkdocs/docs/examples/nlohmann_json_deserialize_enum_strict.cpp +++ b/docs/mkdocs/docs/examples/nlohmann_json_deserialize_enum_strict.cpp @@ -1,13 +1,6 @@ #include #include -#if !defined(JSON_NOEXCEPTION) && !defined(JSON_THROW_USER) && !defined(JSON_THROW) - #define JSON_THROW(exception) throw exception -#else - #include - #define JSON_THROW(exception) std::abort() -#endif - using json = nlohmann::json; namespace ns diff --git a/include/nlohmann/detail/macro_scope.hpp b/include/nlohmann/detail/macro_scope.hpp index ff302dc486..8bf6119712 100644 --- a/include/nlohmann/detail/macro_scope.hpp +++ b/include/nlohmann/detail/macro_scope.hpp @@ -168,7 +168,6 @@ #define JSON_INTERNAL_CATCH(exception) catch(exception) #else #include - std::forward(exception); #define JSON_THROW(exception) std::abort() #define JSON_TRY if(true) #define JSON_CATCH(exception) if(false) @@ -249,7 +248,13 @@ namespace detail template [[noreturn]] inline void json_throw_from_serialize_macro(T&& exception) { - JSON_THROW(std::forward(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 diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index de3902b21c..3559d49661 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -2534,7 +2534,6 @@ JSON_HEDLEY_DIAGNOSTIC_POP #define JSON_INTERNAL_CATCH(exception) catch(exception) #else #include - std::forward(exception); #define JSON_THROW(exception) std::abort() #define JSON_TRY if(true) #define JSON_CATCH(exception) if(false) @@ -2615,7 +2614,13 @@ namespace detail template [[noreturn]] inline void json_throw_from_serialize_macro(T&& exception) { - JSON_THROW(std::forward(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