From 65fbbc5588e34e0a907b385bb199f6d11d95b37d Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 17 Oct 2026 07:27:13 +0200 Subject: [PATCH] Fix GCC and clang-tidy warnings in the JSON pointer speedups Signed-off-by: Niels Lohmann --- include/nlohmann/detail/json_pointer.hpp | 7 ++++--- single_include/nlohmann/json.hpp | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index f3c262cba..4aa31c0d3 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -599,7 +600,7 @@ class json_pointer std::memcpy(&w, data + i, size - i); } h = (h ^ w) * 0x9E3779B97F4A7C15ULL; - return static_cast(h ^ (h >> 29u)); + return detail::conditional_static_cast(h ^ (h >> 29u)); } void grow() @@ -1275,7 +1276,7 @@ class json_pointer std::size_t pos = buf.size(); do { - buf[--pos] = static_cast('0' + i % 10); + buf[--pos] = static_cast('0' + (i % 10)); i /= 10; } while (i != 0); @@ -1327,7 +1328,7 @@ class json_pointer // flatten `v`, whose path is `path`: primitives and empty containers // are added to the result right away; other containers get a frame auto& object = *result.m_data.m_value.object; - typename BasicJsonType::object_t::iterator hint = object.end(); + auto hint = object.end(); const auto enter = [&stack, &path, &object, &hint](const BasicJsonType & v) { switch (v.type()) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 013d5b5f8..b16eccd40 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20995,6 +20995,8 @@ NLOHMANN_JSON_NAMESPACE_END // #include +// #include + // #include // #include @@ -21571,7 +21573,7 @@ class json_pointer std::memcpy(&w, data + i, size - i); } h = (h ^ w) * 0x9E3779B97F4A7C15ULL; - return static_cast(h ^ (h >> 29u)); + return detail::conditional_static_cast(h ^ (h >> 29u)); } void grow() @@ -22247,7 +22249,7 @@ class json_pointer std::size_t pos = buf.size(); do { - buf[--pos] = static_cast('0' + i % 10); + buf[--pos] = static_cast('0' + (i % 10)); i /= 10; } while (i != 0); @@ -22299,7 +22301,7 @@ class json_pointer // flatten `v`, whose path is `path`: primitives and empty containers // are added to the result right away; other containers get a frame auto& object = *result.m_data.m_value.object; - typename BasicJsonType::object_t::iterator hint = object.end(); + auto hint = object.end(); const auto enter = [&stack, &path, &object, &hint](const BasicJsonType & v) { switch (v.type())