Skip to content

Commit 2898659

Browse files
committed
address review comment
Signed-off-by: Harinath Nampally <[email protected]>
1 parent 32cbaee commit 2898659

File tree

2 files changed

+26
-36
lines changed

2 files changed

+26
-36
lines changed

include/nlohmann/detail/macro_scope.hpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,6 @@
1717

1818
#include <nlohmann/detail/abi_macros.hpp>
1919

20-
NLOHMANN_JSON_NAMESPACE_BEGIN
21-
namespace detail
22-
{
23-
template<typename T>
24-
[[noreturn]] inline void throw_if_exceptions_enabled(T&& exception)
25-
{
26-
#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) || defined(EXCEPTIONS)
27-
throw std::forward<T>(exception);
28-
#else
29-
// Forward the exception (even if unused) and abort
30-
std::forward<T>(exception);
31-
std::abort();
32-
#endif
33-
}
34-
} // namespace detail
35-
NLOHMANN_JSON_NAMESPACE_END
3620

3721
// exclude unsupported compilers
3822
#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
@@ -272,6 +256,17 @@ NLOHMANN_JSON_NAMESPACE_END
272256
e = ((it != std::end(m)) ? it : std::begin(m))->first; \
273257
}
274258

259+
NLOHMANN_JSON_NAMESPACE_BEGIN
260+
namespace detail
261+
{
262+
template<typename T>
263+
[[noreturn]] inline void json_throw_from_serialize_macro(T&& exception)
264+
{
265+
static_cast<void>(exception);
266+
JSON_THROW(std::forward<T>(exception));
267+
}
268+
} // namespace detail
269+
NLOHMANN_JSON_NAMESPACE_END
275270
/*!
276271
@brief macro to briefly define a mapping between an enum and JSON
277272
@def NLOHMANN_JSON_SERIALIZE_ENUM_STRICT
@@ -292,7 +287,7 @@ NLOHMANN_JSON_NAMESPACE_END
292287
}); \
293288
if (it == std::end(m)) { \
294289
auto value = static_cast<typename std::underlying_type<ENUM_TYPE>::type>(e); \
295-
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)); \
290+
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)); \
296291
} \
297292
j = it->second; \
298293
} \
@@ -309,7 +304,7 @@ NLOHMANN_JSON_NAMESPACE_END
309304
return ej_pair.second == j; \
310305
}); \
311306
if (it == std::end(m)) \
312-
nlohmann::detail::throw_if_exceptions_enabled(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't deserialize - invalid json value : ", j.dump()), &j)); \
307+
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)); \
313308
e = it->first; \
314309
}
315310

single_include/nlohmann/json.hpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,22 +2383,6 @@ JSON_HEDLEY_DIAGNOSTIC_POP
23832383
// #include <nlohmann/detail/abi_macros.hpp>
23842384

23852385

2386-
NLOHMANN_JSON_NAMESPACE_BEGIN
2387-
namespace detail
2388-
{
2389-
template<typename T>
2390-
[[noreturn]] inline void throw_if_exceptions_enabled(T&& exception)
2391-
{
2392-
#if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) || defined(EXCEPTIONS)
2393-
throw std::forward<T>(exception);
2394-
#else
2395-
// Forward the exception (even if unused) and abort
2396-
std::forward<T>(exception);
2397-
std::abort();
2398-
#endif
2399-
}
2400-
} // namespace detail
2401-
NLOHMANN_JSON_NAMESPACE_END
24022386

24032387
// exclude unsupported compilers
24042388
#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
@@ -2638,6 +2622,17 @@ NLOHMANN_JSON_NAMESPACE_END
26382622
e = ((it != std::end(m)) ? it : std::begin(m))->first; \
26392623
}
26402624

2625+
NLOHMANN_JSON_NAMESPACE_BEGIN
2626+
namespace detail
2627+
{
2628+
template<typename T>
2629+
[[noreturn]] inline void json_throw_from_serialize_macro(T&& exception)
2630+
{
2631+
static_cast<void>(exception);
2632+
JSON_THROW(std::forward<T>(exception));
2633+
}
2634+
} // namespace detail
2635+
NLOHMANN_JSON_NAMESPACE_END
26412636
/*!
26422637
@brief macro to briefly define a mapping between an enum and JSON
26432638
@def NLOHMANN_JSON_SERIALIZE_ENUM_STRICT
@@ -2658,7 +2653,7 @@ NLOHMANN_JSON_NAMESPACE_END
26582653
}); \
26592654
if (it == std::end(m)) { \
26602655
auto value = static_cast<typename std::underlying_type<ENUM_TYPE>::type>(e); \
2661-
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)); \
2656+
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)); \
26622657
} \
26632658
j = it->second; \
26642659
} \
@@ -2675,7 +2670,7 @@ NLOHMANN_JSON_NAMESPACE_END
26752670
return ej_pair.second == j; \
26762671
}); \
26772672
if (it == std::end(m)) \
2678-
nlohmann::detail::throw_if_exceptions_enabled(nlohmann::detail::type_error::create(302, nlohmann::detail::concat("can't deserialize - invalid json value : ", j.dump()), &j)); \
2673+
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)); \
26792674
e = it->first; \
26802675
}
26812676

0 commit comments

Comments
 (0)