Fix the clang-tidy findings in the tests and headers of the API stack

- make_move_iterator_if_mutable takes the iterator by const reference
  (performance-unnecessary-value-param).
- throw_patch_missing_member builds its message without a local that
  is unused with JSON_NOEXCEPTION (bugprone-unused-local-non-trivial-variable).
- Tests: NOLINT the copies that test the copy constructor and the
  constant mt19937 seed, NOLINT the deliberate "\xC3" "a" literal
  concatenation, use references for the const views in
  unit-throw_messages and return {} from its lambda.

A full clang-tidy 22 run over all 107 test translation units is clean.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-10-16 11:04:30 +02:00
1 parent c759a73ced
commit cb9634301e
7 files changed
+23 -24

No files matched your search

+5 -5
View File
@@ -198,11 +198,11 @@ TEST_CASE("copy constructor and destructor across value types")
const json src_uint = 7u;
const json src_float = 2.5;
json c_null(src_null);
json c_bool(src_bool);
json c_int(src_int);
json c_uint(src_uint);
json c_float(src_float);
json c_null(src_null); // NOLINT(performance-unnecessary-copy-initialization): tests the copy constructor
json c_bool(src_bool); // NOLINT(performance-unnecessary-copy-initialization): tests the copy constructor
json c_int(src_int); // NOLINT(performance-unnecessary-copy-initialization): tests the copy constructor
json c_uint(src_uint); // NOLINT(performance-unnecessary-copy-initialization): tests the copy constructor
json c_float(src_float); // NOLINT(performance-unnecessary-copy-initialization): tests the copy constructor
CHECK(c_null.is_null());
CHECK(c_bool == true);
+1 -1
View File
@@ -1230,7 +1230,7 @@ TEST_CASE("JSON pointer array index tokens match strtoull semantics")
SECTION("random tokens")
{
std::mt19937 gen(42);
std::mt19937 gen(42); // NOLINT(cert-msc32-c,cert-msc51-cpp,bugprone-random-generator-seed): reproducible
const std::string alphabet = "0123456789012345678901234567890123456789-+ ex";
for (int i = 0; i < 5000; ++i)
{
+1 -1
View File
@@ -1435,7 +1435,7 @@ TEST_CASE("invalid UTF-8 at every position is handled like the reference")
"\xF4\x90\x80\x80",
// sequences cut short by ASCII, a control character, a quote, a
// backslash, DEL, or the lead byte of a well-formed character
"\xC3" "a", "\xE2\x82" "\n", "\xE2\x82\"", "\xF0\x9F\x98\\", "\xC3\x7F", "\xC3\xC3\xA4", "\xE2\xF0\x9F\x98\x80",
"\xC3" "a", "\xE2\x82" "\n", "\xE2\x82\"", "\xF0\x9F\x98\\", "\xC3\x7F", "\xC3\xC3\xA4", "\xE2\xF0\x9F\x98\x80", // NOLINT(bugprone-suspicious-missing-comma): "\xC3" "a" ends the hex escape
// truncated sequences
"\xC3", "\xE2\x82", "\xF0\x9F\x98"
};
+8 -7
View File
@@ -54,8 +54,8 @@ TEST_CASE("exception messages of out-of-line throw sites")
SECTION("at")
{
const json carr = arr;
const json cobj = obj;
const json& carr = arr;
const json& cobj = obj;
CHECK_MSG((void)arr.at(static_cast<json::size_type>(10)), "[json.exception.out_of_range.401] array index 10 is out of range");
CHECK_MSG((void)carr.at(static_cast<json::size_type>(3)), "[json.exception.out_of_range.401] array index 3 is out of range");
CHECK_MSG((void)num.at(static_cast<json::size_type>(0)), "[json.exception.type_error.304] cannot use at() with number");
@@ -65,7 +65,7 @@ TEST_CASE("exception messages of out-of-line throw sites")
CHECK_MSG((void)num.at("a"), "[json.exception.type_error.304] cannot use at() with number");
nlohmann::ordered_json oobj = {{"a", 1}};
const nlohmann::ordered_json coobj = oobj;
const nlohmann::ordered_json& coobj = oobj;
CHECK_MSG((void)oobj.at("z"), "[json.exception.out_of_range.403] key 'z' not found");
CHECK_MSG((void)coobj.at("z"), "[json.exception.out_of_range.403] key 'z' not found");
CHECK_MSG((void)coobj.at(std::string("zz")), "[json.exception.out_of_range.403] key 'zz' not found");
@@ -97,7 +97,7 @@ TEST_CASE("exception messages of out-of-line throw sites")
#if !defined(JSON_NOEXCEPTION) // patch_msg() catches the exceptions, which JSON_NOEXCEPTION turns into std::abort()
SECTION("patch")
{
const auto patch_msg = [](const char* doc, const char* patch)
const auto patch_msg = [](const char* doc, const char* patch) -> std::string
{
try
{
@@ -110,8 +110,9 @@ TEST_CASE("exception messages of out-of-line throw sites")
// and with JSON_DIAGNOSTIC_POSITIONS its position like "(bytes 0-2) "; drop both
std::string msg = e.what();
for (const char* marker :
{" (/", " (bytes "
})
{
" (/", " (bytes "
})
{
const auto pos = msg.find(marker);
if (pos != std::string::npos)
@@ -121,7 +122,7 @@ TEST_CASE("exception messages of out-of-line throw sites")
}
return msg;
}
return std::string();
return {};
};
CHECK(patch_msg("{}", "{}") == "[json.exception.parse_error.104] parse error: JSON patch must be an array of objects");