Skip to content

Commit c35d260

Browse files
authored
Suppress Clang-Tidy warnings (nlohmann#4276)
1 parent 6a064e0 commit c35d260

12 files changed

+36
-35
lines changed

.clang-tidy

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Checks: '*,
4545
-modernize-type-traits,
4646
-modernize-use-constraints,
4747
-modernize-use-nodiscard,
48+
-modernize-use-std-numbers,
4849
-modernize-use-trailing-return-type,
4950
-performance-enum-size,
5051
-readability-function-cognitive-complexity,

include/nlohmann/detail/input/json_sax.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,9 @@ class json_sax_dom_callback_parser
632632
/// stack to model hierarchy of values
633633
std::vector<BasicJsonType*> ref_stack {};
634634
/// stack to manage which values to keep
635-
std::vector<bool> keep_stack {};
635+
std::vector<bool> keep_stack {}; // NOLINT(readability-redundant-member-init)
636636
/// stack to manage which object keys to keep
637-
std::vector<bool> key_keep_stack {};
637+
std::vector<bool> key_keep_stack {}; // NOLINT(readability-redundant-member-init)
638638
/// helper to hold the reference for the next object element
639639
BasicJsonType* object_element = nullptr;
640640
/// whether a syntax error occurred

include/nlohmann/json.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4847,7 +4847,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
48474847
auto it = val.m_data.m_value.object->find(member);
48484848

48494849
// context-sensitive error message
4850-
const auto error_msg = (op == "op") ? "operation" : detail::concat("operation '", op, '\'');
4850+
const auto error_msg = (op == "op") ? "operation" : detail::concat("operation '", op, '\''); // NOLINT(bugprone-unused-local-non-trivial-variable)
48514851

48524852
// check if desired value is present
48534853
if (JSON_HEDLEY_UNLIKELY(it == val.m_data.m_value.object->end()))

single_include/nlohmann/json.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -7271,9 +7271,9 @@ class json_sax_dom_callback_parser
72717271
/// stack to model hierarchy of values
72727272
std::vector<BasicJsonType*> ref_stack {};
72737273
/// stack to manage which values to keep
7274-
std::vector<bool> keep_stack {};
7274+
std::vector<bool> keep_stack {}; // NOLINT(readability-redundant-member-init)
72757275
/// stack to manage which object keys to keep
7276-
std::vector<bool> key_keep_stack {};
7276+
std::vector<bool> key_keep_stack {}; // NOLINT(readability-redundant-member-init)
72777277
/// helper to hold the reference for the next object element
72787278
BasicJsonType* object_element = nullptr;
72797279
/// whether a syntax error occurred
@@ -24150,7 +24150,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
2415024150
auto it = val.m_data.m_value.object->find(member);
2415124151

2415224152
// context-sensitive error message
24153-
const auto error_msg = (op == "op") ? "operation" : detail::concat("operation '", op, '\'');
24153+
const auto error_msg = (op == "op") ? "operation" : detail::concat("operation '", op, '\''); // NOLINT(bugprone-unused-local-non-trivial-variable)
2415424154

2415524155
// check if desired value is present
2415624156
if (JSON_HEDLEY_UNLIKELY(it == val.m_data.m_value.object->end()))

tests/src/unit-alt-string.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class alt_string
158158
}
159159

160160
private:
161-
std::string str_impl {};
161+
std::string str_impl {}; // NOLINT(readability-redundant-member-init)
162162

163163
friend bool operator<(const char* /*op1*/, const alt_string& /*op2*/) noexcept;
164164
};

tests/src/unit-class_parser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class SaxEventLogger
124124
return false;
125125
}
126126

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

tests/src/unit-convenience.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct alt_string_iter
5555
return *this;
5656
}
5757

58-
std::string impl{};
58+
std::string impl{}; // NOLINT(readability-redundant-member-init)
5959
};
6060

6161
struct alt_string_data
@@ -91,7 +91,7 @@ struct alt_string_data
9191
return *this;
9292
}
9393

94-
std::string impl{};
94+
std::string impl{}; // NOLINT(readability-redundant-member-init)
9595
};
9696

9797
void check_escaped(const char* original, const char* escaped = "", bool ensure_ascii = false);

tests/src/unit-deserialization.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
125125
return false;
126126
}
127127

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

131131
struct SaxEventLoggerExitAfterStartObject : public SaxEventLogger

tests/src/unit-readme.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ TEST_CASE("README" * doctest::skip())
115115
auto j3 = json::parse(R"({"happy": true, "pi": 3.141})");
116116

117117
// explicit conversion to string
118-
std::string const s = j.dump(); // {\"happy\":true,\"pi\":3.141}
118+
std::string const s = j.dump(); // NOLINT(bugprone-unused-local-non-trivial-variable) // {\"happy\":true,\"pi\":3.141}
119119

120120
// serialization with pretty printing
121121
// pass in the amount of spaces to indent
@@ -152,7 +152,7 @@ TEST_CASE("README" * doctest::skip())
152152
}
153153

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

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

254254
// etc.
255255

256-
std::string const vs = js.get<std::string>();
256+
std::string const vs = js.get<std::string>(); // NOLINT(bugprone-unused-local-non-trivial-variable)
257257
bool vb = jb.get<bool>();
258258
CHECK(vb == true);
259259
int vi = jn.get<int>();

tests/src/unit-regression2.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ struct Data
9090
: a(std::move(a_))
9191
, b(std::move(b_))
9292
{}
93-
std::string a{};
94-
std::string b{};
93+
std::string a{}; // NOLINT(readability-redundant-member-init)
94+
std::string b{}; // NOLINT(readability-redundant-member-init)
9595
};
9696

9797
void from_json(const json& j, Data& data);
@@ -218,7 +218,7 @@ class Foo
218218
class FooBar
219219
{
220220
public:
221-
Foo foo{};
221+
Foo foo{}; // NOLINT(readability-redundant-member-init)
222222
};
223223

224224
inline void from_json(const nlohmann::json& j, FooBar& fb)
@@ -240,7 +240,7 @@ struct for_3171_base // NOLINT(cppcoreguidelines-special-member-functions)
240240
j.at("str").get_to(str);
241241
}
242242

243-
std::string str{};
243+
std::string str{}; // NOLINT(readability-redundant-member-init)
244244
};
245245

246246
struct for_3171_derived : public for_3171_base
@@ -622,8 +622,8 @@ TEST_CASE("regression tests 2")
622622
// see https://github.com/nlohmann/json/pull/2181#issuecomment-653326060
623623
const json j{{"x", "test"}};
624624
const std::string defval = "default value";
625-
auto val = j.value("x", defval);
626-
auto val2 = j.value("y", defval);
625+
auto val = j.value("x", defval); // NOLINT(bugprone-unused-local-non-trivial-variable)
626+
auto val2 = j.value("y", defval); // NOLINT(bugprone-unused-local-non-trivial-variable)
627627
}
628628

629629
SECTION("issue #2293 - eof doesn't cause parsing to stop")

tests/src/unit-udt.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ struct address
5252

5353
struct person
5454
{
55-
age m_age{};
56-
name m_name{};
57-
country m_country{};
55+
age m_age{}; // NOLINT(readability-redundant-member-init)
56+
name m_name{}; // NOLINT(readability-redundant-member-init)
57+
country m_country{}; // NOLINT(readability-redundant-member-init)
5858
person() = default;
5959
person(const age& a, name n, const country& c) : m_age(a), m_name(std::move(n)), m_country(c) {}
6060
};
6161

6262
struct contact
6363
{
64-
person m_person{};
65-
address m_address{};
64+
person m_person{}; // NOLINT(readability-redundant-member-init)
65+
address m_address{}; // NOLINT(readability-redundant-member-init)
6666
contact() = default;
6767
contact(person p, address a) : m_person(std::move(p)), m_address(std::move(a)) {}
6868
};
@@ -71,9 +71,9 @@ enum class book_id : std::uint64_t;
7171

7272
struct contact_book
7373
{
74-
name m_book_name{};
74+
name m_book_name{}; // NOLINT(readability-redundant-member-init)
7575
book_id m_book_id{};
76-
std::vector<contact> m_contacts{};
76+
std::vector<contact> m_contacts{}; // NOLINT(readability-redundant-member-init)
7777
contact_book() = default;
7878
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)) {}
7979
};
@@ -343,7 +343,7 @@ namespace udt
343343
{
344344
struct legacy_type
345345
{
346-
std::string number{};
346+
std::string number{}; // NOLINT(readability-redundant-member-init)
347347
legacy_type() = default;
348348
legacy_type(std::string n) : number(std::move(n)) {}
349349
};
@@ -616,7 +616,7 @@ struct small_pod
616616

617617
struct non_pod
618618
{
619-
std::string s{};
619+
std::string s{}; // NOLINT(readability-redundant-member-init)
620620
non_pod() = default;
621621
non_pod(std::string S) : s(std::move(S)) {}
622622
};

tests/src/unit-udt_macro.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace persons
1818
class person_with_private_data
1919
{
2020
private:
21-
std::string name{};
21+
std::string name{}; // NOLINT(readability-redundant-member-init)
2222
int age = 0;
2323
json metadata = nullptr;
2424

@@ -41,7 +41,7 @@ class person_with_private_data
4141
class person_with_private_data_2
4242
{
4343
private:
44-
std::string name{};
44+
std::string name{}; // NOLINT(readability-redundant-member-init)
4545
int age = 0;
4646
json metadata = nullptr;
4747

@@ -77,7 +77,7 @@ class person_with_private_data_2
7777
class person_without_private_data_1
7878
{
7979
public:
80-
std::string name{};
80+
std::string name{}; // NOLINT(readability-redundant-member-init)
8181
int age = 0;
8282
json metadata = nullptr;
8383

@@ -99,7 +99,7 @@ class person_without_private_data_1
9999
class person_without_private_data_2
100100
{
101101
public:
102-
std::string name{};
102+
std::string name{}; // NOLINT(readability-redundant-member-init)
103103
int age = 0;
104104
json metadata = nullptr;
105105

@@ -121,7 +121,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(person_without_private_data_2, age, name, met
121121
class person_without_private_data_3
122122
{
123123
public:
124-
std::string name{};
124+
std::string name{}; // NOLINT(readability-redundant-member-init)
125125
int age = 0;
126126
json metadata = nullptr;
127127

0 commit comments

Comments
 (0)