Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress Clang-Tidy warnings #4276

Merged
merged 8 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions include/nlohmann/detail/input/json_sax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,9 @@ class json_sax_dom_callback_parser
/// stack to model hierarchy of values
std::vector<BasicJsonType*> ref_stack {};
/// stack to manage which values to keep
std::vector<bool> keep_stack {};
std::vector<bool> keep_stack {}; // NOLINT(readability-redundant-member-init)
/// stack to manage which object keys to keep
std::vector<bool> key_keep_stack {};
std::vector<bool> 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
Expand Down
2 changes: 1 addition & 1 deletion include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
6 changes: 3 additions & 3 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7271,9 +7271,9 @@ class json_sax_dom_callback_parser
/// stack to model hierarchy of values
std::vector<BasicJsonType*> ref_stack {};
/// stack to manage which values to keep
std::vector<bool> keep_stack {};
std::vector<bool> keep_stack {}; // NOLINT(readability-redundant-member-init)
/// stack to manage which object keys to keep
std::vector<bool> key_keep_stack {};
std::vector<bool> 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
Expand Down Expand Up @@ -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()))
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-alt-string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-class_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class SaxEventLogger
return false;
}

std::vector<std::string> events {};
std::vector<std::string> events {}; // NOLINT(readability-redundant-member-init)
bool errored = false;
};

Expand Down
4 changes: 2 additions & 2 deletions tests/src/unit-convenience.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
return false;
}

std::vector<std::string> events {};
std::vector<std::string> events {}; // NOLINT(readability-redundant-member-init)
};

struct SaxEventLoggerExitAfterStartObject : public SaxEventLogger
Expand Down
8 changes: 4 additions & 4 deletions tests/src/unit-readme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -152,7 +152,7 @@ TEST_CASE("README" * doctest::skip())
}

// getter/setter
const auto tmp = j[0].get<std::string>();
const auto tmp = j[0].get<std::string>(); // NOLINT(bugprone-unused-local-non-trivial-variable)
j[1] = 42;
bool foo{j.at(2)};
CHECK(foo == true);
Expand Down Expand Up @@ -237,7 +237,7 @@ TEST_CASE("README" * doctest::skip())
// strings
std::string const s1 = "Hello, world!";
json const js = s1;
auto s2 = js.get<std::string>();
auto s2 = js.get<std::string>(); // NOLINT(bugprone-unused-local-non-trivial-variable)

// Booleans
bool const b1 = true;
Expand All @@ -253,7 +253,7 @@ TEST_CASE("README" * doctest::skip())

// etc.

std::string const vs = js.get<std::string>();
std::string const vs = js.get<std::string>(); // NOLINT(bugprone-unused-local-non-trivial-variable)
bool vb = jb.get<bool>();
CHECK(vb == true);
int vi = jn.get<int>();
Expand Down
12 changes: 6 additions & 6 deletions tests/src/unit-regression2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
18 changes: 9 additions & 9 deletions tests/src/unit-udt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {}
};
Expand All @@ -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<contact> m_contacts{};
std::vector<contact> m_contacts{}; // NOLINT(readability-redundant-member-init)
contact_book() = default;
contact_book(name n, book_id i, std::vector<contact> c) : m_book_name(std::move(n)), m_book_id(i), m_contacts(std::move(c)) {}
};
Expand Down Expand Up @@ -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)) {}
};
Expand Down Expand Up @@ -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)) {}
};
Expand Down
10 changes: 5 additions & 5 deletions tests/src/unit-udt_macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand Down
Loading