From 0ad9cc3c1de6fcda207a790ff1e73a3c795c1a1d Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 30 Sep 2026 17:57:41 +0200 Subject: [PATCH] Fix stale and malformed NOLINT comments json_sax.hpp named "-warnings-as-errors" in the NOLINT list on the two JSON_ASSERT(false) lines; that is the suffix clang-tidy appends to a diagnostic tag under WarningsAsErrors, not a check name, and every other JSON_ASSERT(false) omits it. unit-capacity.cpp carried 30 "// NOLINT(misc-const-correctness)" comments on "json j = ...;" declarations that are all used with non-const members afterwards, so the check has nothing to report there. unit-constructor2.cpp used a blanket "// NOLINT: access after move is OK here" on a use-after-move that hides every check on the line; naming bugprone-use-after-move and hicpp-invalid-access-moved keeps the intent once those checks are re-enabled (#5724). Signed-off-by: Niels Lohmann #5725 item 10 --- include/nlohmann/detail/input/json_sax.hpp | 4 +- single_include/nlohmann/json.hpp | 4 +- tests/src/unit-capacity.cpp | 60 +++++++++++----------- tests/src/unit-constructor2.cpp | 2 +- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp index 962913610..3d91ac7c6 100644 --- a/include/nlohmann/detail/input/json_sax.hpp +++ b/include/nlohmann/detail/input/json_sax.hpp @@ -440,7 +440,7 @@ class json_sax_dom_parser } default: // LCOV_EXCL_LINE // Handle all possible types discretely, default handler should never be reached. - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert,-warnings-as-errors) LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } } } @@ -891,7 +891,7 @@ class json_sax_dom_callback_parser } default: // LCOV_EXCL_LINE // Handle all possible types discretely, default handler should never be reached. - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert,-warnings-as-errors) LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } } } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index c3b3dc88d..e9d09c478 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -11857,7 +11857,7 @@ class json_sax_dom_parser } default: // LCOV_EXCL_LINE // Handle all possible types discretely, default handler should never be reached. - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert,-warnings-as-errors) LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } } } @@ -12308,7 +12308,7 @@ class json_sax_dom_callback_parser } default: // LCOV_EXCL_LINE // Handle all possible types discretely, default handler should never be reached. - JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert,-warnings-as-errors) LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE } } } diff --git a/tests/src/unit-capacity.cpp b/tests/src/unit-capacity.cpp index 98fcd0089..5465ebc74 100644 --- a/tests/src/unit-capacity.cpp +++ b/tests/src/unit-capacity.cpp @@ -17,7 +17,7 @@ TEST_CASE("capacity") { SECTION("boolean") { - json j = true; // NOLINT(misc-const-correctness) + json j = true; const json j_const = true; SECTION("result of empty") @@ -35,7 +35,7 @@ TEST_CASE("capacity") SECTION("string") { - json j = "hello world"; // NOLINT(misc-const-correctness) + json j = "hello world"; const json j_const = "hello world"; SECTION("result of empty") @@ -55,7 +55,7 @@ TEST_CASE("capacity") { SECTION("empty array") { - json j = json::array(); // NOLINT(misc-const-correctness) + json j = json::array(); const json j_const = json::array(); SECTION("result of empty") @@ -73,7 +73,7 @@ TEST_CASE("capacity") SECTION("filled array") { - json j = {1, 2, 3}; // NOLINT(misc-const-correctness) + json j = {1, 2, 3}; const json j_const = {1, 2, 3}; SECTION("result of empty") @@ -94,7 +94,7 @@ TEST_CASE("capacity") { SECTION("empty object") { - json j = json::object(); // NOLINT(misc-const-correctness) + json j = json::object(); const json j_const = json::object(); SECTION("result of empty") @@ -112,7 +112,7 @@ TEST_CASE("capacity") SECTION("filled object") { - json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness) + json j = {{"one", 1}, {"two", 2}, {"three", 3}}; const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}}; SECTION("result of empty") @@ -131,7 +131,7 @@ TEST_CASE("capacity") SECTION("number (integer)") { - json j = -23; // NOLINT(misc-const-correctness) + json j = -23; const json j_const = -23; SECTION("result of empty") @@ -149,7 +149,7 @@ TEST_CASE("capacity") SECTION("number (unsigned)") { - json j = 23u; // NOLINT(misc-const-correctness) + json j = 23u; const json j_const = 23u; SECTION("result of empty") @@ -167,7 +167,7 @@ TEST_CASE("capacity") SECTION("number (float)") { - json j = 23.42; // NOLINT(misc-const-correctness) + json j = 23.42; const json j_const = 23.42; SECTION("result of empty") @@ -185,7 +185,7 @@ TEST_CASE("capacity") SECTION("null") { - json j = nullptr; // NOLINT(misc-const-correctness) + json j = nullptr; const json j_const = nullptr; SECTION("result of empty") @@ -206,7 +206,7 @@ TEST_CASE("capacity") { SECTION("boolean") { - json j = true; // NOLINT(misc-const-correctness) + json j = true; const json j_const = true; SECTION("result of size") @@ -226,7 +226,7 @@ TEST_CASE("capacity") SECTION("string") { - json j = "hello world"; // NOLINT(misc-const-correctness) + json j = "hello world"; const json j_const = "hello world"; SECTION("result of size") @@ -248,7 +248,7 @@ TEST_CASE("capacity") { SECTION("empty array") { - json j = json::array(); // NOLINT(misc-const-correctness) + json j = json::array(); const json j_const = json::array(); SECTION("result of size") @@ -268,7 +268,7 @@ TEST_CASE("capacity") SECTION("filled array") { - json j = {1, 2, 3}; // NOLINT(misc-const-correctness) + json j = {1, 2, 3}; const json j_const = {1, 2, 3}; SECTION("result of size") @@ -291,7 +291,7 @@ TEST_CASE("capacity") { SECTION("empty object") { - json j = json::object(); // NOLINT(misc-const-correctness) + json j = json::object(); const json j_const = json::object(); SECTION("result of size") @@ -311,7 +311,7 @@ TEST_CASE("capacity") SECTION("filled object") { - json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness) + json j = {{"one", 1}, {"two", 2}, {"three", 3}}; const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}}; SECTION("result of size") @@ -332,7 +332,7 @@ TEST_CASE("capacity") SECTION("number (integer)") { - json j = -23; // NOLINT(misc-const-correctness) + json j = -23; const json j_const = -23; SECTION("result of size") @@ -352,7 +352,7 @@ TEST_CASE("capacity") SECTION("number (unsigned)") { - json j = 23u; // NOLINT(misc-const-correctness) + json j = 23u; const json j_const = 23u; SECTION("result of size") @@ -372,7 +372,7 @@ TEST_CASE("capacity") SECTION("number (float)") { - json j = 23.42; // NOLINT(misc-const-correctness) + json j = 23.42; const json j_const = 23.42; SECTION("result of size") @@ -392,7 +392,7 @@ TEST_CASE("capacity") SECTION("null") { - json j = nullptr; // NOLINT(misc-const-correctness) + json j = nullptr; const json j_const = nullptr; SECTION("result of size") @@ -415,7 +415,7 @@ TEST_CASE("capacity") { SECTION("boolean") { - json j = true; // NOLINT(misc-const-correctness) + json j = true; const json j_const = true; SECTION("result of max_size") @@ -427,7 +427,7 @@ TEST_CASE("capacity") SECTION("string") { - json j = "hello world"; // NOLINT(misc-const-correctness) + json j = "hello world"; const json j_const = "hello world"; SECTION("result of max_size") @@ -441,7 +441,7 @@ TEST_CASE("capacity") { SECTION("empty array") { - json j = json::array(); // NOLINT(misc-const-correctness) + json j = json::array(); const json j_const = json::array(); SECTION("result of max_size") @@ -453,7 +453,7 @@ TEST_CASE("capacity") SECTION("filled array") { - json j = {1, 2, 3}; // NOLINT(misc-const-correctness) + json j = {1, 2, 3}; const json j_const = {1, 2, 3}; SECTION("result of max_size") @@ -468,7 +468,7 @@ TEST_CASE("capacity") { SECTION("empty object") { - json j = json::object(); // NOLINT(misc-const-correctness) + json j = json::object(); const json j_const = json::object(); SECTION("result of max_size") @@ -480,7 +480,7 @@ TEST_CASE("capacity") SECTION("filled object") { - json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness) + json j = {{"one", 1}, {"two", 2}, {"three", 3}}; const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}}; SECTION("result of max_size") @@ -493,7 +493,7 @@ TEST_CASE("capacity") SECTION("number (integer)") { - json j = -23; // NOLINT(misc-const-correctness) + json j = -23; const json j_const = -23; SECTION("result of max_size") @@ -505,7 +505,7 @@ TEST_CASE("capacity") SECTION("number (unsigned)") { - json j = 23u; // NOLINT(misc-const-correctness) + json j = 23u; const json j_const = 23u; SECTION("result of max_size") @@ -517,7 +517,7 @@ TEST_CASE("capacity") SECTION("number (float)") { - json j = 23.42; // NOLINT(misc-const-correctness) + json j = 23.42; const json j_const = 23.42; SECTION("result of max_size") @@ -529,7 +529,7 @@ TEST_CASE("capacity") SECTION("null") { - json j = nullptr; // NOLINT(misc-const-correctness) + json j = nullptr; const json j_const = nullptr; SECTION("result of max_size") diff --git a/tests/src/unit-constructor2.cpp b/tests/src/unit-constructor2.cpp index a2c7e19bf..27bdcccd9 100644 --- a/tests/src/unit-constructor2.cpp +++ b/tests/src/unit-constructor2.cpp @@ -85,7 +85,7 @@ TEST_CASE("other constructors and destructor") CHECK(j.type() == json::value_t::object); const json k(std::move(j)); CHECK(k.type() == json::value_t::object); - CHECK(j.type() == json::value_t::null); // NOLINT: access after move is OK here + CHECK(j.type() == json::value_t::null); // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved) access after move is OK here } SECTION("copy assignment")