From b3c9deebb7e649c70a08f94a7ec834d6b5f67682 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 10 Oct 2026 01:26:28 +0200 Subject: [PATCH] Fix clang-tidy 22 findings in unit-json_view_image.cpp and image.hpp Signed-off-by: Niels Lohmann (cherry picked from commit 611faf2c8846e56f20743455623893b537edbce4) --- include/nlohmann/detail/view/image.hpp | 10 +++++++++- tests/src/unit-json_view_image.cpp | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/detail/view/image.hpp b/include/nlohmann/detail/view/image.hpp index d228034f7..91ff5acc8 100644 --- a/include/nlohmann/detail/view/image.hpp +++ b/include/nlohmann/detail/view/image.hpp @@ -437,7 +437,15 @@ inline bool check_float_ranges(std::vector& ranges, const unsigned { std::sort(ranges.begin(), ranges.end(), [](const float_range & a, const float_range & b) { - return a.off != b.off ? a.off < b.off : (a.len != b.len ? a.len < b.len : a.extra < b.extra); + if (a.off != b.off) + { + return a.off < b.off; + } + if (a.len != b.len) + { + return a.len < b.len; + } + return a.extra < b.extra; }); std::size_t end = 0; std::size_t i = 0; diff --git a/tests/src/unit-json_view_image.cpp b/tests/src/unit-json_view_image.cpp index 406e3b8a6..7d01f18e9 100644 --- a/tests/src/unit-json_view_image.cpp +++ b/tests/src/unit-json_view_image.cpp @@ -56,7 +56,7 @@ const char* const check_failed = "[json.exception.parse_error.116] parse error: std::string read_file(const std::string& name) { - std::ifstream f(std::string(TEST_DATA_DIRECTORY) + name, std::ios::binary); + const std::ifstream f(std::string(TEST_DATA_DIRECTORY) + name, std::ios::binary); std::stringstream ss; ss << f.rdbuf(); return ss.str(); @@ -325,7 +325,7 @@ TEST_CASE("json_view images: round trips") // exceed the probe limit, so the object has none and is searched // linearly; 40 of 200 keys in one slot (512 slots): a table with a // long chain - const struct + const struct // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays): an unnamed type { std::size_t slots; std::size_t colliding; @@ -342,7 +342,7 @@ TEST_CASE("json_view images: round trips") text.pop_back(); for (const std::string& key : duplicated) { - text += ",\"" + key + "\":\"last\""; + text += ",\"" + key + R"(":"last")"; } text += "}"; const json_document d = json_document::parse(text);