Skip to content

Commit e17bf40

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

File tree

2 files changed

+24
-36
lines changed

2 files changed

+24
-36
lines changed

include/nlohmann/detail/macro_scope.hpp

Lines changed: 12 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,16 @@ 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+
JSON_THROW(std::forward<T>(exception));
266+
}
267+
} // namespace detail
268+
NLOHMANN_JSON_NAMESPACE_END
275269
/*!
276270
@brief macro to briefly define a mapping between an enum and JSON
277271
@def NLOHMANN_JSON_SERIALIZE_ENUM_STRICT
@@ -292,7 +286,7 @@ NLOHMANN_JSON_NAMESPACE_END
292286
}); \
293287
if (it == std::end(m)) { \
294288
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)); \
289+
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)); \
296290
} \
297291
j = it->second; \
298292
} \
@@ -309,7 +303,7 @@ NLOHMANN_JSON_NAMESPACE_END
309303
return ej_pair.second == j; \
310304
}); \
311305
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)); \
306+
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)); \
313307
e = it->first; \
314308
}
315309

single_include/nlohmann/json.hpp

Lines changed: 12 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,16 @@ 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+
JSON_THROW(std::forward<T>(exception));
2632+
}
2633+
} // namespace detail
2634+
NLOHMANN_JSON_NAMESPACE_END
26412635
/*!
26422636
@brief macro to briefly define a mapping between an enum and JSON
26432637
@def NLOHMANN_JSON_SERIALIZE_ENUM_STRICT
@@ -2658,7 +2652,7 @@ NLOHMANN_JSON_NAMESPACE_END
26582652
}); \
26592653
if (it == std::end(m)) { \
26602654
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)); \
2655+
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)); \
26622656
} \
26632657
j = it->second; \
26642658
} \
@@ -2675,7 +2669,7 @@ NLOHMANN_JSON_NAMESPACE_END
26752669
return ej_pair.second == j; \
26762670
}); \
26772671
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)); \
2672+
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)); \
26792673
e = it->first; \
26802674
}
26812675

0 commit comments

Comments
 (0)