From 694bfd1b4e5e0abea11b58e06bc65b09c01f8c9f Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 29 Sep 2026 00:32:20 +0200 Subject: [PATCH] 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 --- include/nlohmann/detail/view/macro_scope.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/nlohmann/detail/view/macro_scope.hpp b/include/nlohmann/detail/view/macro_scope.hpp index 0aad401ac..a2d2c52c3 100644 --- a/include/nlohmann/detail/view/macro_scope.hpp +++ b/include/nlohmann/detail/view/macro_scope.hpp @@ -42,7 +42,9 @@ #define NLOHMANN_VIEW_THROW(exception) throw exception #else #include - #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(exception), std::abort()) #endif #if defined(JSON_THROW_USER) #undef NLOHMANN_VIEW_THROW