Address two Clang-Tidy findings the custom container tests exposed

Both come from instantiating basic_json with containers other than the
default ones, and neither shows up with the Clang-Tidy version available
outside CI:

- insert(const_iterator, basic_json&&) forwards its by-value iterator to
  the const-reference overload. performance-unnecessary-value-param asks
  for the copy to be a move; it only fires for an iterator that is not
  trivially copyable, as std::deque's is not. The NOLINT on the function
  does not cover it, because the finding is reported where the parameter
  is used rather than where it is declared. Move it, which is what the
  check asks for and is a (very small) improvement in its own right.

- cppcoreguidelines-use-enum-class rejects the unnamed enum that shadowed
  the inherited key_compare member type. An enum class would not do, since
  it declares a type of that name and the probe would find it again; a
  member function declaration hides the name just as well.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann
2026-08-28 19:49:20 +00:00
parent 5a2b8a274d
commit 0da083744a
3 changed files with 4 additions and 3 deletions
+1 -1
View File
@@ -3420,7 +3420,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @sa https://json.nlohmann.me/api/basic_json/insert/
iterator insert(const_iterator pos, basic_json&& val) // NOLINT(performance-unnecessary-value-param)
{
return insert(pos, val);
return insert(std::move(pos), val);
}
/// @brief inserts copies of element into array
+1 -1
View File
@@ -24894,7 +24894,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @sa https://json.nlohmann.me/api/basic_json/insert/
iterator insert(const_iterator pos, basic_json&& val) // NOLINT(performance-unnecessary-value-param)
{
return insert(pos, val);
return insert(std::move(pos), val);
}
/// @brief inserts copies of element into array
+2 -1
View File
@@ -37,7 +37,8 @@ struct no_key_compare_map : std::map<Key, T, Compare, Allocator>
using base_t = std::map<Key, T, Compare, Allocator>;
using base_t::base_t;
enum { key_compare }; // shadows base_t::key_compare, which is a type
// shadows base_t::key_compare, which is a type; never defined or called
void key_compare();
};
using no_key_compare_json = nlohmann::basic_json<no_key_compare_map>;