Skip to content

Commit 9dd05aa

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

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
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

0 commit comments

Comments
 (0)