From 4b9fc0ad76c79cd627ad93c5e1f45f9b7aafc77c Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 20 Jul 2026 19:00:24 +0000 Subject: [PATCH] Satisfy clang-tidy: parenthesize math and drop unused forwarding reference The CI clang-tidy (newer than the locally available version) reported two additional checks on the new code: - readability-math-missing-parentheses: parenthesize the (a * b) + c digit accumulations in number_parse.hpp. - cppcoreguidelines-missing-std-forward: the contiguous-byte-container input_adapter overload took a forwarding reference but only reads data()/size() and never forwards it. It is already disjoint from the generic container overload via SFINAE, so a plain const& is correct and clearer (and keeps the container alive for the whole parse just as before). No behavior change; char_type and routing are unchanged (std::string and std::vector still take the pointer adapter with char/uint8_t char_type), CBOR/MsgPack round-trips and the 2M number fuzz still pass. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01AXcDtEma2PjxgmPS9cQGzA Signed-off-by: Niels Lohmann --- include/nlohmann/detail/input/input_adapters.hpp | 2 +- include/nlohmann/detail/input/number_parse.hpp | 8 ++++---- single_include/nlohmann/json.hpp | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/nlohmann/detail/input/input_adapters.hpp b/include/nlohmann/detail/input/input_adapters.hpp index 7f87fc4c0..a2e395dde 100644 --- a/include/nlohmann/detail/input/input_adapters.hpp +++ b/include/nlohmann/detail/input/input_adapters.hpp @@ -658,7 +658,7 @@ typename container_input_adapter_factory_impl::container_input_adapter_factory::value, int > = 0 > -auto input_adapter(ContainerType && container) +auto input_adapter(const ContainerType& container) -> decltype(input_adapter(container.data(), container.data() + container.size())) { return input_adapter(container.data(), container.data() + container.size()); diff --git a/include/nlohmann/detail/input/number_parse.hpp b/include/nlohmann/detail/input/number_parse.hpp index 15245b52e..83a7f5237 100644 --- a/include/nlohmann/detail/input/number_parse.hpp +++ b/include/nlohmann/detail/input/number_parse.hpp @@ -54,7 +54,7 @@ bool parse_integer_unsigned(const char* first, const char* last, NumberUnsignedT { return false; } - x = x * 10u + digit; + x = (x * 10u) + digit; } value = static_cast(x); // reject values that do not round-trip into a narrower NumberUnsignedType @@ -84,7 +84,7 @@ bool parse_integer_signed(const char* first, const char* last, NumberIntegerType { return false; } - magnitude = magnitude * 10u + digit; + magnitude = (magnitude * 10u) + digit; } const std::int64_t x = (magnitude == limit) ? (std::numeric_limits::min)() @@ -146,7 +146,7 @@ bool parse_float_fast(const char* first, const char* last, DecimalPointType deci { return false; // significand may not fit into uint64_t } - significand = significand * 10u + static_cast(c - '0'); + significand = (significand * 10u) + static_cast(c - '0'); ++num_digits; fractional_digits += static_cast(seen_dot); } @@ -189,7 +189,7 @@ bool parse_float_fast(const char* first, const char* last, DecimalPointType deci { return false; } - exponent = exponent * 10 + (*p - '0'); + exponent = (exponent * 10) + (*p - '0'); any_exp_digit = true; if (JSON_HEDLEY_UNLIKELY(exponent > 9999)) { diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index be3da54ca..9ec86686d 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -7645,7 +7645,7 @@ typename container_input_adapter_factory_impl::container_input_adapter_factory::value, int > = 0 > -auto input_adapter(ContainerType && container) +auto input_adapter(const ContainerType& container) -> decltype(input_adapter(container.data(), container.data() + container.size())) { return input_adapter(container.data(), container.data() + container.size()); @@ -7837,7 +7837,7 @@ bool parse_integer_unsigned(const char* first, const char* last, NumberUnsignedT { return false; } - x = x * 10u + digit; + x = (x * 10u) + digit; } value = static_cast(x); // reject values that do not round-trip into a narrower NumberUnsignedType @@ -7867,7 +7867,7 @@ bool parse_integer_signed(const char* first, const char* last, NumberIntegerType { return false; } - magnitude = magnitude * 10u + digit; + magnitude = (magnitude * 10u) + digit; } const std::int64_t x = (magnitude == limit) ? (std::numeric_limits::min)() @@ -7929,7 +7929,7 @@ bool parse_float_fast(const char* first, const char* last, DecimalPointType deci { return false; // significand may not fit into uint64_t } - significand = significand * 10u + static_cast(c - '0'); + significand = (significand * 10u) + static_cast(c - '0'); ++num_digits; fractional_digits += static_cast(seen_dot); } @@ -7972,7 +7972,7 @@ bool parse_float_fast(const char* first, const char* last, DecimalPointType deci { return false; } - exponent = exponent * 10 + (*p - '0'); + exponent = (exponent * 10) + (*p - '0'); any_exp_digit = true; if (JSON_HEDLEY_UNLIKELY(exponent > 9999)) {