diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp index 020115531..05ae82370 100644 --- a/include/nlohmann/detail/conversions/to_json.hpp +++ b/include/nlohmann/detail/conversions/to_json.hpp @@ -52,13 +52,13 @@ namespace detail // const (e.g., std::set): libstdc++ before GCC 5 defines the reference of a // std::move_iterator as value_type&&, which cannot bind to a const element template -std::move_iterator make_move_iterator_if_mutable_impl(Iterator it, std::true_type /*mutable*/) +std::move_iterator make_move_iterator_if_mutable_impl(const Iterator& it, std::true_type /*mutable*/) { return std::make_move_iterator(it); } template -Iterator make_move_iterator_if_mutable_impl(Iterator it, std::false_type /*mutable*/) +Iterator make_move_iterator_if_mutable_impl(const Iterator& it, std::false_type /*mutable*/) { return it; } @@ -68,7 +68,7 @@ using is_mutable_iterator = std::integral_constant < bool, !std::is_const())>::type>::value >; template -auto make_move_iterator_if_mutable(Iterator it) +auto make_move_iterator_if_mutable(const Iterator& it) -> decltype(make_move_iterator_if_mutable_impl(it, is_mutable_iterator {})) { return make_move_iterator_if_mutable_impl(it, is_mutable_iterator {}); diff --git a/include/nlohmann/detail/exceptions.hpp b/include/nlohmann/detail/exceptions.hpp index b2b5f36dd..7d7f4e038 100644 --- a/include/nlohmann/detail/exceptions.hpp +++ b/include/nlohmann/detail/exceptions.hpp @@ -494,8 +494,7 @@ JSON_HEDLEY_NO_RETURN JSON_HEDLEY_NEVER_INLINE void throw_patch_missing_member(c static_cast(string_type); static_cast(val); // context-sensitive error message - const std::string error_msg = (op == "op") ? std::string("operation") : concat("operation '", op, '\''); - JSON_THROW(parse_error::create(exception_id::patch_invalid_operation, 0, concat(error_msg, string_type ? " must have string member '" : " must have member '", member, "'"), &val)); + JSON_THROW(parse_error::create(exception_id::patch_invalid_operation, 0, concat((op == "op") ? std::string("operation") : concat("operation '", op, '\''), string_type ? " must have string member '" : " must have member '", member, "'"), &val)); } template diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 0db7d067a..4debe551f 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -5795,8 +5795,7 @@ JSON_HEDLEY_NO_RETURN JSON_HEDLEY_NEVER_INLINE void throw_patch_missing_member(c static_cast(string_type); static_cast(val); // context-sensitive error message - const std::string error_msg = (op == "op") ? std::string("operation") : concat("operation '", op, '\''); - JSON_THROW(parse_error::create(exception_id::patch_invalid_operation, 0, concat(error_msg, string_type ? " must have string member '" : " must have member '", member, "'"), &val)); + JSON_THROW(parse_error::create(exception_id::patch_invalid_operation, 0, concat((op == "op") ? std::string("operation") : concat("operation '", op, '\''), string_type ? " must have string member '" : " must have member '", member, "'"), &val)); } template @@ -7209,13 +7208,13 @@ namespace detail // const (e.g., std::set): libstdc++ before GCC 5 defines the reference of a // std::move_iterator as value_type&&, which cannot bind to a const element template -std::move_iterator make_move_iterator_if_mutable_impl(Iterator it, std::true_type /*mutable*/) +std::move_iterator make_move_iterator_if_mutable_impl(const Iterator& it, std::true_type /*mutable*/) { return std::make_move_iterator(it); } template -Iterator make_move_iterator_if_mutable_impl(Iterator it, std::false_type /*mutable*/) +Iterator make_move_iterator_if_mutable_impl(const Iterator& it, std::false_type /*mutable*/) { return it; } @@ -7225,7 +7224,7 @@ using is_mutable_iterator = std::integral_constant < bool, !std::is_const())>::type>::value >; template -auto make_move_iterator_if_mutable(Iterator it) +auto make_move_iterator_if_mutable(const Iterator& it) -> decltype(make_move_iterator_if_mutable_impl(it, is_mutable_iterator {})) { return make_move_iterator_if_mutable_impl(it, is_mutable_iterator {}); diff --git a/tests/src/unit-constructor2.cpp b/tests/src/unit-constructor2.cpp index 9b2fb3df6..f17d0ad3a 100644 --- a/tests/src/unit-constructor2.cpp +++ b/tests/src/unit-constructor2.cpp @@ -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); diff --git a/tests/src/unit-json_pointer.cpp b/tests/src/unit-json_pointer.cpp index 46444f3f2..7748a375a 100644 --- a/tests/src/unit-json_pointer.cpp +++ b/tests/src/unit-json_pointer.cpp @@ -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) { diff --git a/tests/src/unit-serialization.cpp b/tests/src/unit-serialization.cpp index 2ad4f2eda..b6608a49a 100644 --- a/tests/src/unit-serialization.cpp +++ b/tests/src/unit-serialization.cpp @@ -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" }; diff --git a/tests/src/unit-throw_messages.cpp b/tests/src/unit-throw_messages.cpp index f9f8a5445..d7546cc93 100644 --- a/tests/src/unit-throw_messages.cpp +++ b/tests/src/unit-throw_messages.cpp @@ -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(10)), "[json.exception.out_of_range.401] array index 10 is out of range"); CHECK_MSG((void)carr.at(static_cast(3)), "[json.exception.out_of_range.401] array index 3 is out of range"); CHECK_MSG((void)num.at(static_cast(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");