From ab4f6461b8d26168b9b2d12bcc5c2e7e5559c0a0 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 29 Sep 2026 22:56:26 +0200 Subject: [PATCH 1/2] Fix CI: useless cast in the growth of the view's node index GCC -Werror=useless-cast (ci_test_gcc on Linux x86-64) rejected static_cast(guess + (guess / 4) + 64): the sum is a std::uint64_t prvalue, the same type as std::size_t there, while the cast is needed where std::size_t is 32 bits wide. Cast a named variable instead, which GCC does not report. The build stopped at an earlier error before, so the previous CI run did not show this one. Signed-off-by: Niels Lohmann --- include/nlohmann/detail/view/builder.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/nlohmann/detail/view/builder.hpp b/include/nlohmann/detail/view/builder.hpp index 2e0151b31..8393b9c8d 100644 --- a/include/nlohmann/detail/view/builder.hpp +++ b/include/nlohmann/detail/view/builder.hpp @@ -195,8 +195,9 @@ class builder { const std::uint64_t done = static_cast(at - b) + 1; const std::uint64_t guess = static_cast(n) * static_cast(e - b + 1) / done; + const std::uint64_t grown = guess + (guess / 4) + 64; // a variable: GCC calls a cast of the sum useless where std::uint64_t is std::size_t doc.tape_size = n; - doc.reserve((std::max)(static_cast(guess + (guess / 4) + 64), n + (n / 2) + 64)); + doc.reserve((std::max)(static_cast(grown), n + (n / 2) + 64)); return doc.tape; } From dbbe96c42cbd69f889fd1b3b6e13d101d678ca74 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 29 Sep 2026 23:05:48 +0200 Subject: [PATCH 2/2] Fix CI: useless cast in the array index check of the view's JSON pointers GCC -Werror=useless-cast on Linux x86-64 rejected static_cast((std::numeric_limits::max)()), as both are the same type there. Compare without the cast: std::size_t converts to std::uint64_t implicitly on every platform. Signed-off-by: Niels Lohmann --- include/nlohmann/detail/view/pointer.hpp | 2 +- single_include/nlohmann/json_view.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/nlohmann/detail/view/pointer.hpp b/include/nlohmann/detail/view/pointer.hpp index 2c7b1e4db..d2ac497d7 100644 --- a/include/nlohmann/detail/view/pointer.hpp +++ b/include/nlohmann/detail/view/pointer.hpp @@ -69,7 +69,7 @@ index_status array_index(const StringType& s, std::size_t& idx) noexcept } v = (v * 10) + d; } - if (v >= static_cast((std::numeric_limits::max)())) + if (v >= (std::numeric_limits::max)()) // (std::size_t converts to std::uint64_t implicitly) { return index_status::too_large; } diff --git a/single_include/nlohmann/json_view.hpp b/single_include/nlohmann/json_view.hpp index bc5391894..627c64ab4 100644 --- a/single_include/nlohmann/json_view.hpp +++ b/single_include/nlohmann/json_view.hpp @@ -2464,7 +2464,7 @@ index_status array_index(const StringType& s, std::size_t& idx) noexcept } v = (v * 10) + d; } - if (v >= static_cast((std::numeric_limits::max)())) + if (v >= (std::numeric_limits::max)()) // (std::size_t converts to std::uint64_t implicitly) { return index_status::too_large; }