address review comment
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
This commit is contained in:
parent
c6d9ea0b51
commit
44449851eb
@ -17,6 +17,34 @@
|
||||
|
||||
#include <nlohmann/detail/abi_macros.hpp>
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail
|
||||
{
|
||||
template<typename T>
|
||||
[[noreturn]] inline void throw_if_exceptions_enabled(T&& exception)
|
||||
{
|
||||
#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) || defined(EXCEPTIONS)
|
||||
throw std::forward<T>(exception);
|
||||
#else
|
||||
std::abort();
|
||||
#endif
|
||||
}
|
||||
} // namespace detail
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
|
||||
// exclude unsupported compilers
|
||||
#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
|
||||
#if defined(__clang__)
|
||||
#if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
|
||||
#error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
|
||||
#endif
|
||||
#elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
|
||||
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
|
||||
#error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// exclude unsupported compilers
|
||||
#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
|
||||
#if defined(__clang__)
|
||||
@ -262,7 +290,7 @@
|
||||
}); \
|
||||
if (it == std::end(m)) { \
|
||||
auto value = static_cast<typename std::underlying_type<ENUM_TYPE>::type>(e); \
|
||||
JSON_THROW(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't serialize - enum value ", std::to_string(value), " out of range"), &j)); \
|
||||
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)); \
|
||||
} \
|
||||
j = it->second; \
|
||||
} \
|
||||
@ -279,7 +307,7 @@
|
||||
return ej_pair.second == j; \
|
||||
}); \
|
||||
if (it == std::end(m)) \
|
||||
JSON_THROW(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't deserialize - invalid json value : ", j.dump()), &j)); \
|
||||
nlohmann::detail::throw_if_exceptions_enabled(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't deserialize - invalid json value : ", j.dump()), &j)); \
|
||||
e = it->first; \
|
||||
}
|
||||
|
||||
|
||||
@ -2383,6 +2383,34 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
||||
// #include <nlohmann/detail/abi_macros.hpp>
|
||||
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
namespace detail
|
||||
{
|
||||
template<typename T>
|
||||
[[noreturn]] inline void throw_if_exceptions_enabled(T&& exception)
|
||||
{
|
||||
#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) || defined(EXCEPTIONS)
|
||||
throw std::forward<T>(exception);
|
||||
#else
|
||||
std::abort();
|
||||
#endif
|
||||
}
|
||||
} // namespace detail
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
|
||||
// exclude unsupported compilers
|
||||
#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
|
||||
#if defined(__clang__)
|
||||
#if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
|
||||
#error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
|
||||
#endif
|
||||
#elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
|
||||
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
|
||||
#error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// exclude unsupported compilers
|
||||
#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
|
||||
#if defined(__clang__)
|
||||
@ -2628,7 +2656,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
||||
}); \
|
||||
if (it == std::end(m)) { \
|
||||
auto value = static_cast<typename std::underlying_type<ENUM_TYPE>::type>(e); \
|
||||
JSON_THROW(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't serialize - enum value ", std::to_string(value), " out of range"), &j)); \
|
||||
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)); \
|
||||
} \
|
||||
j = it->second; \
|
||||
} \
|
||||
@ -2645,7 +2673,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
||||
return ej_pair.second == j; \
|
||||
}); \
|
||||
if (it == std::end(m)) \
|
||||
JSON_THROW(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't deserialize - invalid json value : ", j.dump()), &j)); \
|
||||
nlohmann::detail::throw_if_exceptions_enabled(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't deserialize - invalid json value : ", j.dump()), &j)); \
|
||||
e = it->first; \
|
||||
}
|
||||
|
||||
|
||||
@ -1657,13 +1657,6 @@ TEST_CASE("JSON to enum mapping")
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(JSON_NOEXCEPTION) && !defined(JSON_THROW_USER) && !defined(JSON_THROW)
|
||||
#define JSON_THROW(exception) throw exception
|
||||
#else
|
||||
#include <cstdlib>
|
||||
#define JSON_THROW(exception) std::abort()
|
||||
#endif
|
||||
|
||||
enum class cards_strict {kreuz, pik, herz, karo};
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - false positive
|
||||
@ -1729,9 +1722,6 @@ TEST_CASE("JSON to enum mapping")
|
||||
CHECK_THROWS_WITH_AS(j.template get<TaskStateStrict>(), "[json.exception.type_error.302] can't deserialize - invalid json value : \"foo\"", json::type_error);
|
||||
}
|
||||
}
|
||||
#if defined(JSON_THROW)
|
||||
#undef JSON_THROW
|
||||
#endif
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
#ifndef JSON_USE_IMPLICIT_CONVERSIONS
|
||||
|
||||
Loading…
Reference in New Issue
Block a user