From a4556e826245dbc944883f5da45a735b7b37303f Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 29 Sep 2026 22:27:24 +0200 Subject: [PATCH 1/2] Fix CI: unused parse result and find() == npos in the Eisel-Lemire tests GCC (-Werror=unused-result) rejected CHECK_THROWS_WITH_AS(json::parse(...)) because parse() is [[nodiscard]]; assign the result to a dummy json as the other tests do. clang-tidy flagged longer.find('.') == npos with abseil-string-find-str-contains; store the position in a variable first. Signed-off-by: Niels Lohmann --- tests/src/unit-class_lexer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/src/unit-class_lexer.cpp b/tests/src/unit-class_lexer.cpp index 5647f4f46..b56e4bd0b 100644 --- a/tests/src/unit-class_lexer.cpp +++ b/tests/src/unit-class_lexer.cpp @@ -1286,7 +1286,8 @@ TEST_CASE("Eisel-Lemire float conversion") // than the distance to the rounding boundary, so it must not change std::string longer = token; const std::size_t e = longer.find('e'); - const std::string extra = longer.find('.') == std::string::npos ? ".000000000000000000001" : "000000000000000000001"; + const std::size_t dot = longer.find('.'); + const std::string extra = dot == std::string::npos ? ".000000000000000000001" : "000000000000000000001"; longer.insert(e == std::string::npos ? longer.size() : e, extra); CAPTURE(longer); if (eisel_lemire(longer, out)) @@ -1309,7 +1310,8 @@ TEST_CASE("Eisel-Lemire float conversion") CHECK(bits_of(json::parse("-65.613616999999977").get()) == bits_of(-65.613616999999977)); CHECK(bits_of(json::parse("2.2250738585072011e-308").get()) == 0x000FFFFFFFFFFFFFu); CHECK(bits_of(json::parse("4.9406564584124654e-324").get()) == 1u); - CHECK_THROWS_WITH_AS(json::parse("1.7976931348623159e308"), + json _; + CHECK_THROWS_WITH_AS(_ = json::parse("1.7976931348623159e308"), "[json.exception.out_of_range.406] number overflow parsing '1.7976931348623159e308'", json::out_of_range&); } } From 046ad7ebd8bfd7bdb666f8c0164ff15eda9f2900 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 29 Sep 2026 22:29:25 +0200 Subject: [PATCH 2/2] Fix CI: useless casts to std::size_t in the string-scan tests GCC -Werror=useless-cast rejected static_cast(next() % n): on 64-bit Linux std::uint64_t and std::size_t are the same type, while the cast is needed where std::size_t is 32 bits wide. Draw the sizes from a 32-bit value instead, which converts to std::size_t implicitly on every platform. Signed-off-by: Niels Lohmann --- tests/src/unit-class_lexer.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/src/unit-class_lexer.cpp b/tests/src/unit-class_lexer.cpp index 30d8a5679..d8577f206 100644 --- a/tests/src/unit-class_lexer.cpp +++ b/tests/src/unit-class_lexer.cpp @@ -1378,16 +1378,23 @@ TEST_CASE("string scanning kernels") state ^= state << 17u; return state; }; + // the upper half as a 32-bit value: converts to std::size_t implicitly on + // every platform (a cast of std::uint64_t is useless where both are the + // same type, and required where std::size_t is 32 bits wide) + const auto next_small = [&next]() + { + return static_cast(next() >> 32u); + }; for (int round = 0; round < 100000; ++round) { // mostly ordinary text, so that runs span several words - std::string text(static_cast(next() % 8), '.'); - const auto count = static_cast(next() % 12); + std::string text(next_small() % 8u, '.'); + const std::size_t count = next_small() % 12u; for (std::size_t k = 0; k < count; ++k) { - const std::size_t p = (next() % 4 == 0) ? static_cast(next() % pieces.size()) : 0; + const std::size_t p = (next() % 4 == 0) ? next_small() % pieces.size() : 0; text += pieces[p]; - text += std::string(static_cast(next() % 10), 'x'); + text += std::string(next_small() % 10u, 'x'); } const auto* data = reinterpret_cast(text.data()); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) for (std::size_t offset = 0; offset < 3 && offset <= text.size(); ++offset)