From 66bf78819fe89eaa97bfb95286b36f4a418b3fa6 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 20 Jul 2026 10:09:24 +0000 Subject: [PATCH] Fix clang-tidy findings and document JSON_USE_SIMDUTF in the nav - number_parse.hpp: use std::array for the powers-of-ten table (avoid-c-arrays) and `auto` for the cast-initialized result (modernize-use-auto), matching the codebase style (cf. the serializer's utf8d table). Indexing casts keep the -Wsign-conversion build clean. - add JSON_USE_SIMDUTF to the mkdocs navigation so the macro page is reachable. No behavior change; clang-tidy is clean on the new headers and the amalgamation is regenerated. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01AXcDtEma2PjxgmPS9cQGzA Signed-off-by: Niels Lohmann --- docs/mkdocs/mkdocs.yml | 1 + include/nlohmann/detail/input/number_parse.hpp | 16 ++++++++++------ single_include/nlohmann/json.hpp | 16 ++++++++++------ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/docs/mkdocs/mkdocs.yml b/docs/mkdocs/mkdocs.yml index fe786f7d5..3b97424ff 100644 --- a/docs/mkdocs/mkdocs.yml +++ b/docs/mkdocs/mkdocs.yml @@ -296,6 +296,7 @@ nav: - 'JSON_USE_GLOBAL_UDLS': api/macros/json_use_global_udls.md - 'JSON_USE_IMPLICIT_CONVERSIONS': api/macros/json_use_implicit_conversions.md - 'JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON': api/macros/json_use_legacy_discarded_value_comparison.md + - 'JSON_USE_SIMDUTF': api/macros/json_use_simdutf.md - 'NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE, NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT, NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE, NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE, NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT, NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE': api/macros/nlohmann_define_derived_type.md - 'NLOHMANN_DEFINE_TYPE_INTRUSIVE, NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT, NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE': api/macros/nlohmann_define_type_intrusive.md - 'NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE, NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT, NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE': api/macros/nlohmann_define_type_non_intrusive.md diff --git a/include/nlohmann/detail/input/number_parse.hpp b/include/nlohmann/detail/input/number_parse.hpp index 35d80b1a4..15245b52e 100644 --- a/include/nlohmann/detail/input/number_parse.hpp +++ b/include/nlohmann/detail/input/number_parse.hpp @@ -8,6 +8,8 @@ #pragma once +#include // array +#include // size_t #include // int64_t, uint64_t #include // numeric_limits @@ -113,10 +115,12 @@ below). template bool parse_float_fast(const char* first, const char* last, DecimalPointType decimal_point, double& out) noexcept { - static const double powers_of_ten[] = + static const std::array powers_of_ten = { - 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, - 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22 + { + 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, + 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22 + } }; const char* p = first; @@ -208,14 +212,14 @@ bool parse_float_fast(const char* first, const char* last, DecimalPointType deci return false; // significand not exactly representable as double } - double result = static_cast(significand); + auto result = static_cast(significand); if (scale >= 0) { if (JSON_HEDLEY_UNLIKELY(scale > 22)) { return false; } - result *= powers_of_ten[scale]; + result *= powers_of_ten[static_cast(scale)]; } else { @@ -223,7 +227,7 @@ bool parse_float_fast(const char* first, const char* last, DecimalPointType deci { return false; } - result /= powers_of_ten[-scale]; + result /= powers_of_ten[static_cast(-scale)]; } out = negative ? -result : result; return true; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index fd0b25d91..33442ab76 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -7790,6 +7790,8 @@ NLOHMANN_JSON_NAMESPACE_END +#include // array +#include // size_t #include // int64_t, uint64_t #include // numeric_limits @@ -7896,10 +7898,12 @@ below). template bool parse_float_fast(const char* first, const char* last, DecimalPointType decimal_point, double& out) noexcept { - static const double powers_of_ten[] = + static const std::array powers_of_ten = { - 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, - 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22 + { + 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, + 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22 + } }; const char* p = first; @@ -7991,14 +7995,14 @@ bool parse_float_fast(const char* first, const char* last, DecimalPointType deci return false; // significand not exactly representable as double } - double result = static_cast(significand); + auto result = static_cast(significand); if (scale >= 0) { if (JSON_HEDLEY_UNLIKELY(scale > 22)) { return false; } - result *= powers_of_ten[scale]; + result *= powers_of_ten[static_cast(scale)]; } else { @@ -8006,7 +8010,7 @@ bool parse_float_fast(const char* first, const char* last, DecimalPointType deci { return false; } - result /= powers_of_ten[-scale]; + result /= powers_of_ten[static_cast(-scale)]; } out = negative ? -result : result; return true;