From 1e80e54468557b0cdf95254e955a5045b4e492f4 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 10 Oct 2026 01:19:05 +0200 Subject: [PATCH] Fix clang-tidy 22 findings in the json_view headers Silence bugprone-casting-through-void for the SSE loads (a reinterpret_cast would trip -Wcast-align=strict), use auto for a cast initialiser, add parentheses to a mixed expression, and name bugprone-std-namespace-modification in the NOLINTs of the tuple_size/tuple_element specialisations. Signed-off-by: Niels Lohmann (cherry picked from commit 0effbaa7a21210b4150cbb5c122060b45dec0b28) --- include/nlohmann/detail/view/lookup.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/nlohmann/detail/view/lookup.hpp b/include/nlohmann/detail/view/lookup.hpp index 3b3314329..35c3fbdd9 100644 --- a/include/nlohmann/detail/view/lookup.hpp +++ b/include/nlohmann/detail/view/lookup.hpp @@ -120,6 +120,24 @@ const node* find_member(const document_data& d, const node* object, const char* return nullptr; } +/// whether an integer type is accepted as an array index by the view's +/// operator[] and at(): every integer type but bool and size_t, which has its +/// own overload +template +struct is_index_type : std::integral_constant < bool, + std::is_integral::value && !std::is_same::value && !std::is_same::value > +{}; + +/// an integer as an index: negative values, and values that do not fit a +/// size_t, map to the largest size_t (out of range for every array) +template +SizeType to_index(IntegerType idx) noexcept +{ + const IntegerType zero = 0; + const auto result = static_cast(idx); // NOLINT(bugprone-signed-char-misuse,cert-str34-c): negative values are mapped below + return (idx < zero || static_cast(result) != idx) ? (std::numeric_limits::max)() : result; +} + /// the entry of the element of an array at an index below its size (a link /// in the moved sequences of editable documents) template