From ba05d2c8c2bcaff5c1835e2b675ca52e0c56124b Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 6 Nov 2026 12:10:44 +0100 Subject: [PATCH] Fix CI: clang-tidy, unused result, Infer false positive in tests - unit-deserialization.cpp: raw string literals, and assign the result of parse() in CHECK_THROWS_AS (-Wunused-result) - unit-bson.cpp: mark Infer's NULLPTR_DEREFERENCE on from_bson() with an iterator pair as a false positive Signed-off-by: Niels Lohmann --- tests/src/unit-bson.cpp | 2 ++ tests/src/unit-deserialization.cpp | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/src/unit-bson.cpp b/tests/src/unit-bson.cpp index f7957d566..cf3630b8e 100644 --- a/tests/src/unit-bson.cpp +++ b/tests/src/unit-bson.cpp @@ -1674,6 +1674,8 @@ TEST_CASE("BSON input that cannot be read is discarded by every overload") json _; CHECK_THROWS_AS(_ = json::from_bson(input.begin(), input.end()), json::parse_error&); CHECK(json::from_bson(input, true, false).is_discarded()); + // false positive: Infer takes std::integral_constant::value for a pointer + // @infer-ignore NULLPTR_DEREFERENCE CHECK(json::from_bson(input.begin(), input.end(), true, false).is_discarded()); #ifndef JSON_TEST_DEPRECATED_FUNCTIONS_DELETED CHECK(json::from_bson(input.data(), input.size(), true, false).is_discarded()); diff --git a/tests/src/unit-deserialization.cpp b/tests/src/unit-deserialization.cpp index 0c2ed7ca7..a7e98747e 100644 --- a/tests/src/unit-deserialization.cpp +++ b/tests/src/unit-deserialization.cpp @@ -1457,7 +1457,7 @@ TEST_CASE("deserialization from iterator pairs of std::string and std::vector") // these are read as the pointer range they are, also before C++20 for (const char* text : { - "", " ", "[1, 2.5, \"a\", true, null, {\"k\": [\"v\"]}]", "[1, 2", "{\"a\" 1}", "\"\xC3\xA4\"", "\"\xC3\"", "[1]x", "1e400" + "", " ", R"([1, 2.5, "a", true, null, {"k": ["v"]}])", "[1, 2", R"({"a" 1})", "\"\xC3\xA4\"", "\"\xC3\"", "[1]x", "1e400" }) { check_iterator_pairs(text); @@ -1467,6 +1467,7 @@ TEST_CASE("deserialization from iterator pairs of std::string and std::vector") // an empty range is not dereferenced std::string empty; CHECK_FALSE(json::accept(empty.begin(), empty.end())); - CHECK_THROWS_AS(json::parse(empty.begin(), empty.end()), json::parse_error&); + json _; + CHECK_THROWS_AS(_ = json::parse(empty.begin(), empty.end()), json::parse_error&); } #endif