diff --git a/.clang-tidy b/.clang-tidy index 339360b08..1d1e31f68 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -45,6 +45,7 @@ Checks: '*, -modernize-type-traits, -modernize-use-constraints, -modernize-use-nodiscard, + -modernize-use-std-numbers, -modernize-use-trailing-return-type, -performance-enum-size, -readability-function-cognitive-complexity, diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp index c772521cd..90583d671 100644 --- a/include/nlohmann/detail/input/json_sax.hpp +++ b/include/nlohmann/detail/input/json_sax.hpp @@ -632,9 +632,9 @@ class json_sax_dom_callback_parser /// stack to model hierarchy of values std::vector ref_stack {}; /// stack to manage which values to keep - std::vector keep_stack {}; + std::vector keep_stack {}; // NOLINT(readability-redundant-member-init) /// stack to manage which object keys to keep - std::vector key_keep_stack {}; + std::vector key_keep_stack {}; // NOLINT(readability-redundant-member-init) /// helper to hold the reference for the next object element BasicJsonType* object_element = nullptr; /// whether a syntax error occurred diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 95d6bf1dd..31ca64539 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -4847,7 +4847,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec auto it = val.m_data.m_value.object->find(member); // context-sensitive error message - const auto error_msg = (op == "op") ? "operation" : detail::concat("operation '", op, '\''); + const auto error_msg = (op == "op") ? "operation" : detail::concat("operation '", op, '\''); // NOLINT(bugprone-unused-local-non-trivial-variable) // check if desired value is present if (JSON_HEDLEY_UNLIKELY(it == val.m_data.m_value.object->end())) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index b191bb914..a858728c4 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -7271,9 +7271,9 @@ class json_sax_dom_callback_parser /// stack to model hierarchy of values std::vector ref_stack {}; /// stack to manage which values to keep - std::vector keep_stack {}; + std::vector keep_stack {}; // NOLINT(readability-redundant-member-init) /// stack to manage which object keys to keep - std::vector key_keep_stack {}; + std::vector key_keep_stack {}; // NOLINT(readability-redundant-member-init) /// helper to hold the reference for the next object element BasicJsonType* object_element = nullptr; /// whether a syntax error occurred @@ -24150,7 +24150,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec auto it = val.m_data.m_value.object->find(member); // context-sensitive error message - const auto error_msg = (op == "op") ? "operation" : detail::concat("operation '", op, '\''); + const auto error_msg = (op == "op") ? "operation" : detail::concat("operation '", op, '\''); // NOLINT(bugprone-unused-local-non-trivial-variable) // check if desired value is present if (JSON_HEDLEY_UNLIKELY(it == val.m_data.m_value.object->end())) diff --git a/tests/src/unit-alt-string.cpp b/tests/src/unit-alt-string.cpp index 7efe2e2e9..1d39e8db1 100644 --- a/tests/src/unit-alt-string.cpp +++ b/tests/src/unit-alt-string.cpp @@ -158,7 +158,7 @@ class alt_string } private: - std::string str_impl {}; + std::string str_impl {}; // NOLINT(readability-redundant-member-init) friend bool operator<(const char* /*op1*/, const alt_string& /*op2*/) noexcept; }; diff --git a/tests/src/unit-class_parser.cpp b/tests/src/unit-class_parser.cpp index f766842aa..ee42fb098 100644 --- a/tests/src/unit-class_parser.cpp +++ b/tests/src/unit-class_parser.cpp @@ -124,7 +124,7 @@ class SaxEventLogger return false; } - std::vector events {}; + std::vector events {}; // NOLINT(readability-redundant-member-init) bool errored = false; }; diff --git a/tests/src/unit-convenience.cpp b/tests/src/unit-convenience.cpp index 34bbb02cf..6b50cba0a 100644 --- a/tests/src/unit-convenience.cpp +++ b/tests/src/unit-convenience.cpp @@ -55,7 +55,7 @@ struct alt_string_iter return *this; } - std::string impl{}; + std::string impl{}; // NOLINT(readability-redundant-member-init) }; struct alt_string_data @@ -91,7 +91,7 @@ struct alt_string_data return *this; } - std::string impl{}; + std::string impl{}; // NOLINT(readability-redundant-member-init) }; void check_escaped(const char* original, const char* escaped = "", bool ensure_ascii = false); diff --git a/tests/src/unit-deserialization.cpp b/tests/src/unit-deserialization.cpp index 3bc161f1d..65bb28a22 100644 --- a/tests/src/unit-deserialization.cpp +++ b/tests/src/unit-deserialization.cpp @@ -125,7 +125,7 @@ struct SaxEventLogger : public nlohmann::json_sax return false; } - std::vector events {}; + std::vector events {}; // NOLINT(readability-redundant-member-init) }; struct SaxEventLoggerExitAfterStartObject : public SaxEventLogger diff --git a/tests/src/unit-readme.cpp b/tests/src/unit-readme.cpp index f2a571aac..dc99073e2 100644 --- a/tests/src/unit-readme.cpp +++ b/tests/src/unit-readme.cpp @@ -115,7 +115,7 @@ TEST_CASE("README" * doctest::skip()) auto j3 = json::parse(R"({"happy": true, "pi": 3.141})"); // explicit conversion to string - std::string const s = j.dump(); // {\"happy\":true,\"pi\":3.141} + std::string const s = j.dump(); // NOLINT(bugprone-unused-local-non-trivial-variable) // {\"happy\":true,\"pi\":3.141} // serialization with pretty printing // pass in the amount of spaces to indent @@ -152,7 +152,7 @@ TEST_CASE("README" * doctest::skip()) } // getter/setter - const auto tmp = j[0].get(); + const auto tmp = j[0].get(); // NOLINT(bugprone-unused-local-non-trivial-variable) j[1] = 42; bool foo{j.at(2)}; CHECK(foo == true); @@ -237,7 +237,7 @@ TEST_CASE("README" * doctest::skip()) // strings std::string const s1 = "Hello, world!"; json const js = s1; - auto s2 = js.get(); + auto s2 = js.get(); // NOLINT(bugprone-unused-local-non-trivial-variable) // Booleans bool const b1 = true; @@ -253,7 +253,7 @@ TEST_CASE("README" * doctest::skip()) // etc. - std::string const vs = js.get(); + std::string const vs = js.get(); // NOLINT(bugprone-unused-local-non-trivial-variable) bool vb = jb.get(); CHECK(vb == true); int vi = jn.get(); diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index fab9aae3b..17624d3c6 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -90,8 +90,8 @@ struct Data : a(std::move(a_)) , b(std::move(b_)) {} - std::string a{}; - std::string b{}; + std::string a{}; // NOLINT(readability-redundant-member-init) + std::string b{}; // NOLINT(readability-redundant-member-init) }; void from_json(const json& j, Data& data); @@ -218,7 +218,7 @@ class Foo class FooBar { public: - Foo foo{}; + Foo foo{}; // NOLINT(readability-redundant-member-init) }; inline void from_json(const nlohmann::json& j, FooBar& fb) @@ -240,7 +240,7 @@ struct for_3171_base // NOLINT(cppcoreguidelines-special-member-functions) j.at("str").get_to(str); } - std::string str{}; + std::string str{}; // NOLINT(readability-redundant-member-init) }; struct for_3171_derived : public for_3171_base @@ -622,8 +622,8 @@ TEST_CASE("regression tests 2") // see https://github.com/nlohmann/json/pull/2181#issuecomment-653326060 const json j{{"x", "test"}}; const std::string defval = "default value"; - auto val = j.value("x", defval); - auto val2 = j.value("y", defval); + auto val = j.value("x", defval); // NOLINT(bugprone-unused-local-non-trivial-variable) + auto val2 = j.value("y", defval); // NOLINT(bugprone-unused-local-non-trivial-variable) } SECTION("issue #2293 - eof doesn't cause parsing to stop") diff --git a/tests/src/unit-udt.cpp b/tests/src/unit-udt.cpp index b8437def5..57cf278d8 100644 --- a/tests/src/unit-udt.cpp +++ b/tests/src/unit-udt.cpp @@ -52,17 +52,17 @@ struct address struct person { - age m_age{}; - name m_name{}; - country m_country{}; + age m_age{}; // NOLINT(readability-redundant-member-init) + name m_name{}; // NOLINT(readability-redundant-member-init) + country m_country{}; // NOLINT(readability-redundant-member-init) person() = default; person(const age& a, name n, const country& c) : m_age(a), m_name(std::move(n)), m_country(c) {} }; struct contact { - person m_person{}; - address m_address{}; + person m_person{}; // NOLINT(readability-redundant-member-init) + address m_address{}; // NOLINT(readability-redundant-member-init) contact() = default; contact(person p, address a) : m_person(std::move(p)), m_address(std::move(a)) {} }; @@ -71,9 +71,9 @@ enum class book_id : std::uint64_t; struct contact_book { - name m_book_name{}; + name m_book_name{}; // NOLINT(readability-redundant-member-init) book_id m_book_id{}; - std::vector m_contacts{}; + std::vector m_contacts{}; // NOLINT(readability-redundant-member-init) contact_book() = default; contact_book(name n, book_id i, std::vector c) : m_book_name(std::move(n)), m_book_id(i), m_contacts(std::move(c)) {} }; @@ -343,7 +343,7 @@ namespace udt { struct legacy_type { - std::string number{}; + std::string number{}; // NOLINT(readability-redundant-member-init) legacy_type() = default; legacy_type(std::string n) : number(std::move(n)) {} }; @@ -616,7 +616,7 @@ struct small_pod struct non_pod { - std::string s{}; + std::string s{}; // NOLINT(readability-redundant-member-init) non_pod() = default; non_pod(std::string S) : s(std::move(S)) {} }; diff --git a/tests/src/unit-udt_macro.cpp b/tests/src/unit-udt_macro.cpp index e2383f40d..04631a4dc 100644 --- a/tests/src/unit-udt_macro.cpp +++ b/tests/src/unit-udt_macro.cpp @@ -18,7 +18,7 @@ namespace persons class person_with_private_data { private: - std::string name{}; + std::string name{}; // NOLINT(readability-redundant-member-init) int age = 0; json metadata = nullptr; @@ -41,7 +41,7 @@ class person_with_private_data class person_with_private_data_2 { private: - std::string name{}; + std::string name{}; // NOLINT(readability-redundant-member-init) int age = 0; json metadata = nullptr; @@ -77,7 +77,7 @@ class person_with_private_data_2 class person_without_private_data_1 { public: - std::string name{}; + std::string name{}; // NOLINT(readability-redundant-member-init) int age = 0; json metadata = nullptr; @@ -99,7 +99,7 @@ class person_without_private_data_1 class person_without_private_data_2 { public: - std::string name{}; + std::string name{}; // NOLINT(readability-redundant-member-init) int age = 0; json metadata = nullptr; @@ -121,7 +121,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(person_without_private_data_2, age, name, met class person_without_private_data_3 { public: - std::string name{}; + std::string name{}; // NOLINT(readability-redundant-member-init) int age = 0; json metadata = nullptr;