Keep the arguments of the view's throw helpers used without exceptions

With JSON_NOEXCEPTION, NLOHMANN_VIEW_THROW(e) was std::abort() alone, so
the parameters of the functions that build the exceptions were unused, a
warning that the builds with -Werror turn into an error. The exception is
now evaluated before std::abort(); the program ends anyway.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann
2026-09-29 03:49:30 +02:00
parent a14ac39bdd
commit edfcff33c6
+3 -1
View File
@@ -42,7 +42,9 @@
#define NLOHMANN_VIEW_THROW(exception) throw exception
#else
#include <cstdlib>
#define NLOHMANN_VIEW_THROW(exception) std::abort()
// (the exception is built first, so that the arguments of the throwing
// helpers count as used; the program ends anyway)
#define NLOHMANN_VIEW_THROW(exception) (static_cast<void>(exception), std::abort())
#endif
#if defined(JSON_THROW_USER)
#undef NLOHMANN_VIEW_THROW