From a316738cfa3777ae33dbbda9cd61d2467bb09e36 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 9 Sep 2026 09:50:39 +0200 Subject: [PATCH] Add JSON_HEDLEY_WARN_UNUSED_RESULT to the current accept() overloads (#5471) accept() is a pure query whose only effect is the returned bool; both parse() overloads and the deprecated accept(span_input_adapter&&, ...) overload already carry JSON_HEDLEY_WARN_UNUSED_RESULT, but the two current, recommended accept() overloads were missing it. Add the annotation to match, so discarding accept()'s result now warns under -Wunused-result / [[nodiscard]], as it already does for parse(). Fixes #5407 Signed-off-by: Niels Lohmann --- include/nlohmann/json.hpp | 2 ++ single_include/nlohmann/json.hpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 76d85844b..9b7b9fe81 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -4130,6 +4130,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @brief check if the input is valid JSON /// @sa https://json.nlohmann.me/api/basic_json/accept/ template + JSON_HEDLEY_WARN_UNUSED_RESULT static bool accept(InputType&& i, const bool ignore_comments = false, const bool ignore_trailing_commas = false) @@ -4141,6 +4142,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/accept/ template::value, int> = 0> + JSON_HEDLEY_WARN_UNUSED_RESULT static bool accept(IteratorType first, SentinelType last, const bool ignore_comments = false, const bool ignore_trailing_commas = false) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 28e56f8ac..cc455191a 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -25684,6 +25684,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @brief check if the input is valid JSON /// @sa https://json.nlohmann.me/api/basic_json/accept/ template + JSON_HEDLEY_WARN_UNUSED_RESULT static bool accept(InputType&& i, const bool ignore_comments = false, const bool ignore_trailing_commas = false) @@ -25695,6 +25696,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @sa https://json.nlohmann.me/api/basic_json/accept/ template::value, int> = 0> + JSON_HEDLEY_WARN_UNUSED_RESULT static bool accept(IteratorType first, SentinelType last, const bool ignore_comments = false, const bool ignore_trailing_commas = false)