🚨 fix warnings

This commit is contained in:
Niels Lohmann 2021-01-28 13:51:43 +01:00
parent 866a4c56f0
commit 675f07f5e9
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
12 changed files with 92 additions and 92 deletions

View File

@ -235,7 +235,7 @@ struct allocator_no_forward : std::allocator<T>
{
allocator_no_forward() = default;
template <class U>
allocator_no_forward(allocator_no_forward<U>) {}
allocator_no_forward(allocator_no_forward<U> /*unused*/) {}
template <class U>
struct rebind

View File

@ -437,7 +437,7 @@ TEST_CASE("capacity")
SECTION("boolean")
{
json j = true;
const json j_const(j);
const json j_const = true;
SECTION("result of max_size")
{
@ -449,7 +449,7 @@ TEST_CASE("capacity")
SECTION("string")
{
json j = "hello world";
const json j_const(j);
const json j_const = "hello world";
SECTION("result of max_size")
{
@ -463,7 +463,7 @@ TEST_CASE("capacity")
SECTION("empty array")
{
json j = json::array();
const json j_const(j);
const json j_const = json::array();
SECTION("result of max_size")
{
@ -475,7 +475,7 @@ TEST_CASE("capacity")
SECTION("filled array")
{
json j = {1, 2, 3};
const json j_const(j);
const json j_const = {1, 2, 3};
SECTION("result of max_size")
{
@ -490,7 +490,7 @@ TEST_CASE("capacity")
SECTION("empty object")
{
json j = json::object();
const json j_const(j);
const json j_const = json::object();
SECTION("result of max_size")
{
@ -502,7 +502,7 @@ TEST_CASE("capacity")
SECTION("filled object")
{
json j = {{"one", 1}, {"two", 2}, {"three", 3}};
const json j_const(j);
const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}};
SECTION("result of max_size")
{
@ -515,7 +515,7 @@ TEST_CASE("capacity")
SECTION("number (integer)")
{
json j = -23;
const json j_const(j);
const json j_const = -23;
SECTION("result of max_size")
{
@ -527,7 +527,7 @@ TEST_CASE("capacity")
SECTION("number (unsigned)")
{
json j = 23u;
const json j_const(j);
const json j_const = 23u;
SECTION("result of max_size")
{
@ -539,7 +539,7 @@ TEST_CASE("capacity")
SECTION("number (float)")
{
json j = 23.42;
const json j_const(j);
const json j_const = 23.42;
SECTION("result of max_size")
{
@ -551,7 +551,7 @@ TEST_CASE("capacity")
SECTION("null")
{
json j = nullptr;
const json j_const(j);
const json j_const = nullptr;
SECTION("result of max_size")
{

View File

@ -54,42 +54,42 @@ class SaxCountdown
return events_left-- > 0;
}
bool boolean(bool)
bool boolean(bool /*unused*/)
{
return events_left-- > 0;
}
bool number_integer(json::number_integer_t)
bool number_integer(json::number_integer_t /*unused*/)
{
return events_left-- > 0;
}
bool number_unsigned(json::number_unsigned_t)
bool number_unsigned(json::number_unsigned_t /*unused*/)
{
return events_left-- > 0;
}
bool number_float(json::number_float_t, const std::string&)
bool number_float(json::number_float_t /*unused*/, const std::string& /*unused*/)
{
return events_left-- > 0;
}
bool string(std::string&)
bool string(std::string& /*unused*/)
{
return events_left-- > 0;
}
bool binary(std::vector<std::uint8_t>&)
bool binary(std::vector<std::uint8_t>& /*unused*/)
{
return events_left-- > 0;
}
bool start_object(std::size_t)
bool start_object(std::size_t /*unused*/)
{
return events_left-- > 0;
}
bool key(std::string&)
bool key(std::string& /*unused*/)
{
return events_left-- > 0;
}
@ -99,7 +99,7 @@ class SaxCountdown
return events_left-- > 0;
}
bool start_array(std::size_t)
bool start_array(std::size_t /*unused*/)
{
return events_left-- > 0;
}
@ -109,7 +109,7 @@ class SaxCountdown
return events_left-- > 0;
}
bool parse_error(std::size_t, const std::string&, const json::exception&)
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/)
{
return false;
}
@ -117,7 +117,7 @@ class SaxCountdown
private:
int events_left = 0;
};
}
} // namespace
TEST_CASE("CBOR")
{
@ -294,7 +294,7 @@ TEST_CASE("CBOR")
(static_cast<uint32_t>(result[3]) << 010) +
static_cast<uint32_t>(result[4]);
CHECK(restored == positive);
CHECK(-1ll - restored == i);
CHECK(-1LL - restored == i);
// roundtrip
CHECK(json::from_cbor(result) == j);

View File

@ -395,7 +395,7 @@ TEST_CASE("parser class")
CHECK_THROWS_AS(parser_helper("\uFF01"), json::parse_error&);
CHECK_THROWS_AS(parser_helper("[-4:1,]"), json::parse_error&);
// unescaped control characters
CHECK_THROWS_AS(parser_helper("\"\x00\""), json::parse_error&);
CHECK_THROWS_AS(parser_helper("\"\x00\""), json::parse_error&); // NOLINT(bugprone-string-literal-with-embedded-nul)
CHECK_THROWS_AS(parser_helper("\"\x01\""), json::parse_error&);
CHECK_THROWS_AS(parser_helper("\"\x02\""), json::parse_error&);
CHECK_THROWS_AS(parser_helper("\"\x03\""), json::parse_error&);
@ -427,7 +427,7 @@ TEST_CASE("parser class")
CHECK_THROWS_AS(parser_helper("\"\x1d\""), json::parse_error&);
CHECK_THROWS_AS(parser_helper("\"\x1e\""), json::parse_error&);
CHECK_THROWS_AS(parser_helper("\"\x1f\""), json::parse_error&);
CHECK_THROWS_WITH(parser_helper("\"\x00\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: missing closing quote; last read: '\"'");
CHECK_THROWS_WITH(parser_helper("\"\x00\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: missing closing quote; last read: '\"'"); // NOLINT(bugprone-string-literal-with-embedded-nul)
CHECK_THROWS_WITH(parser_helper("\"\x01\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0001 (SOH) must be escaped to \\u0001; last read: '\"<U+0001>'");
CHECK_THROWS_WITH(parser_helper("\"\x02\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0002 (STX) must be escaped to \\u0002; last read: '\"<U+0002>'");
CHECK_THROWS_WITH(parser_helper("\"\x03\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0003 (ETX) must be escaped to \\u0003; last read: '\"<U+0003>'");
@ -770,7 +770,7 @@ TEST_CASE("parser class")
CHECK(accept_helper("\uFF01") == false);
CHECK(accept_helper("[-4:1,]") == false);
// unescaped control characters
CHECK(accept_helper("\"\x00\"") == false);
CHECK(accept_helper("\"\x00\"") == false); // NOLINT(bugprone-string-literal-with-embedded-nul)
CHECK(accept_helper("\"\x01\"") == false);
CHECK(accept_helper("\"\x02\"") == false);
CHECK(accept_helper("\"\x03\"") == false);

View File

@ -39,63 +39,63 @@ TEST_CASE("other constructors and destructor")
SECTION("object")
{
json j {{"foo", 1}, {"bar", false}};
json k(j);
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
CHECK(j == k);
}
SECTION("array")
{
json j {"foo", 1, 42.23, false};
json k(j);
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
CHECK(j == k);
}
SECTION("null")
{
json j(nullptr);
json k(j);
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
CHECK(j == k);
}
SECTION("boolean")
{
json j(true);
json k(j);
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
CHECK(j == k);
}
SECTION("string")
{
json j("Hello world");
json k(j);
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
CHECK(j == k);
}
SECTION("number (integer)")
{
json j(42);
json k(j);
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
CHECK(j == k);
}
SECTION("number (unsigned)")
{
json j(42u);
json k(j);
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
CHECK(j == k);
}
SECTION("number (floating-point)")
{
json j(42.23);
json k(j);
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
CHECK(j == k);
}
SECTION("binary")
{
json j = json::binary({1, 2, 3});
json k(j);
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
CHECK(j == k);
}
}
@ -106,7 +106,7 @@ TEST_CASE("other constructors and destructor")
CHECK(j.type() == json::value_t::object);
json k(std::move(j));
CHECK(k.type() == json::value_t::object);
CHECK(j.type() == json::value_t::null);
CHECK(j.type() == json::value_t::null); // NOLINT: access after move is OK here
}
SECTION("copy assignment")

View File

@ -48,7 +48,7 @@ TEST_CASE("iterator_wrapper")
json j = { {"A", 1}, {"B", 2} };
int counter = 1;
for (auto i : json::iterator_wrapper(j))
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
{
switch (counter++)
{
@ -125,7 +125,7 @@ TEST_CASE("iterator_wrapper")
json j = { {"A", 1}, {"B", 2} };
int counter = 1;
for (const auto i : json::iterator_wrapper(j))
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
{
switch (counter++)
{
@ -194,7 +194,7 @@ TEST_CASE("iterator_wrapper")
const json j = { {"A", 1}, {"B", 2} };
int counter = 1;
for (auto i : json::iterator_wrapper(j))
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
{
switch (counter++)
{
@ -260,7 +260,7 @@ TEST_CASE("iterator_wrapper")
const json j = { {"A", 1}, {"B", 2} };
int counter = 1;
for (const auto i : json::iterator_wrapper(j))
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
{
switch (counter++)
{
@ -329,7 +329,7 @@ TEST_CASE("iterator_wrapper")
json j = { "A", "B" };
int counter = 1;
for (auto i : json::iterator_wrapper(j))
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
{
switch (counter++)
{
@ -406,7 +406,7 @@ TEST_CASE("iterator_wrapper")
json j = { "A", "B" };
int counter = 1;
for (const auto i : json::iterator_wrapper(j))
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
{
switch (counter++)
{
@ -475,7 +475,7 @@ TEST_CASE("iterator_wrapper")
const json j = { "A", "B" };
int counter = 1;
for (auto i : json::iterator_wrapper(j))
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
{
switch (counter++)
{
@ -541,7 +541,7 @@ TEST_CASE("iterator_wrapper")
const json j = { "A", "B" };
int counter = 1;
for (const auto i : json::iterator_wrapper(j))
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
{
switch (counter++)
{
@ -610,7 +610,7 @@ TEST_CASE("iterator_wrapper")
json j = 1;
int counter = 1;
for (auto i : json::iterator_wrapper(j))
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
{
++counter;
CHECK(i.key() == "");
@ -646,7 +646,7 @@ TEST_CASE("iterator_wrapper")
json j = 1;
int counter = 1;
for (const auto i : json::iterator_wrapper(j))
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
{
++counter;
CHECK(i.key() == "");
@ -679,7 +679,7 @@ TEST_CASE("iterator_wrapper")
const json j = 1;
int counter = 1;
for (auto i : json::iterator_wrapper(j))
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
{
++counter;
CHECK(i.key() == "");
@ -709,7 +709,7 @@ TEST_CASE("iterator_wrapper")
const json j = 1;
int counter = 1;
for (const auto i : json::iterator_wrapper(j))
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
{
++counter;
CHECK(i.key() == "");
@ -745,7 +745,7 @@ TEST_CASE("items()")
json j = { {"A", 1}, {"B", 2} };
int counter = 1;
for (auto i : j.items())
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
{
switch (counter++)
{
@ -822,7 +822,7 @@ TEST_CASE("items()")
json j = { {"A", 1}, {"B", 2} };
int counter = 1;
for (const auto i : j.items())
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
{
switch (counter++)
{
@ -907,7 +907,7 @@ TEST_CASE("items()")
const json j = { {"A", 1}, {"B", 2} };
int counter = 1;
for (auto i : j.items())
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
{
switch (counter++)
{
@ -973,7 +973,7 @@ TEST_CASE("items()")
const json j = { {"A", 1}, {"B", 2} };
int counter = 1;
for (const auto i : j.items())
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
{
switch (counter++)
{
@ -1042,7 +1042,7 @@ TEST_CASE("items()")
json j = { "A", "B" };
int counter = 1;
for (auto i : j.items())
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
{
switch (counter++)
{
@ -1119,7 +1119,7 @@ TEST_CASE("items()")
json j = { "A", "B" };
int counter = 1;
for (const auto i : j.items())
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
{
switch (counter++)
{
@ -1188,7 +1188,7 @@ TEST_CASE("items()")
const json j = { "A", "B" };
int counter = 1;
for (auto i : j.items())
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
{
switch (counter++)
{
@ -1254,7 +1254,7 @@ TEST_CASE("items()")
const json j = { "A", "B" };
int counter = 1;
for (const auto i : j.items())
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
{
switch (counter++)
{
@ -1323,7 +1323,7 @@ TEST_CASE("items()")
json j = 1;
int counter = 1;
for (auto i : j.items())
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
{
++counter;
CHECK(i.key() == "");
@ -1359,7 +1359,7 @@ TEST_CASE("items()")
json j = 1;
int counter = 1;
for (const auto i : j.items())
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
{
++counter;
CHECK(i.key() == "");
@ -1392,7 +1392,7 @@ TEST_CASE("items()")
const json j = 1;
int counter = 1;
for (auto i : j.items())
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
{
++counter;
CHECK(i.key() == "");
@ -1422,7 +1422,7 @@ TEST_CASE("items()")
const json j = 1;
int counter = 1;
for (const auto i : j.items())
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
{
++counter;
CHECK(i.key() == "");

View File

@ -51,7 +51,7 @@ void to_json(json& /*unused*/, pod_bis /*unused*/) {}
void from_json(const json& /*unused*/, pod /*unused*/) noexcept {}
void from_json(const json& /*unused*/, pod_bis /*unused*/) {}
static json* j = nullptr;
json* j = nullptr;
static_assert(noexcept(json{}), "");
static_assert(noexcept(nlohmann::to_json(*j, 2)), "");

View File

@ -135,7 +135,7 @@ TEST_CASE("regression tests 1")
{
SECTION("escape_doublequote")
{
const auto* s = "[\"\\\"foo\\\"\"]";
const auto* s = R"(["\"foo\""])";
json j = json::parse(s);
auto expected = R"(["\"foo\""])"_json;
CHECK(j == expected);

View File

@ -87,7 +87,7 @@ NLOHMANN_JSON_SERIALIZE_ENUM(for_1647,
struct Data
{
Data() = default;
Data(std::string a_, const std::string b_) : a(std::move(a_)), b(b_) {}
Data(std::string a_, std::string b_) : a(std::move(a_)), b(std::move(b_)) {}
std::string a {};
std::string b {};
};
@ -115,7 +115,7 @@ namespace nlohmann
template <>
struct adl_serializer<NonDefaultFromJsonStruct>
{
static NonDefaultFromJsonStruct from_json (json const&) noexcept
static NonDefaultFromJsonStruct from_json (json const& /*unused*/) noexcept
{
return {};
}

View File

@ -51,42 +51,42 @@ class SaxCountdown
return events_left-- > 0;
}
bool boolean(bool)
bool boolean(bool /*unused*/)
{
return events_left-- > 0;
}
bool number_integer(json::number_integer_t)
bool number_integer(json::number_integer_t /*unused*/)
{
return events_left-- > 0;
}
bool number_unsigned(json::number_unsigned_t)
bool number_unsigned(json::number_unsigned_t /*unused*/)
{
return events_left-- > 0;
}
bool number_float(json::number_float_t, const std::string&)
bool number_float(json::number_float_t /*unused*/, const std::string& /*unused*/)
{
return events_left-- > 0;
}
bool string(std::string&)
bool string(std::string& /*unused*/)
{
return events_left-- > 0;
}
bool binary(std::vector<std::uint8_t>&)
bool binary(std::vector<std::uint8_t>& /*unused*/)
{
return events_left-- > 0;
}
bool start_object(std::size_t)
bool start_object(std::size_t /*unused*/)
{
return events_left-- > 0;
}
bool key(std::string&)
bool key(std::string& /*unused*/)
{
return events_left-- > 0;
}
@ -96,7 +96,7 @@ class SaxCountdown
return events_left-- > 0;
}
bool start_array(std::size_t)
bool start_array(std::size_t /*unused*/)
{
return events_left-- > 0;
}
@ -106,7 +106,7 @@ class SaxCountdown
return events_left-- > 0;
}
bool parse_error(std::size_t, const std::string&, const json::exception&)
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/)
{
return false;
}
@ -114,7 +114,7 @@ class SaxCountdown
private:
int events_left = 0;
};
}
} // namespace
TEST_CASE("UBJSON")
{
@ -175,16 +175,16 @@ TEST_CASE("UBJSON")
{
std::vector<int64_t> numbers;
numbers.push_back((std::numeric_limits<int64_t>::min)());
numbers.push_back(-1000000000000000000ll);
numbers.push_back(-100000000000000000ll);
numbers.push_back(-10000000000000000ll);
numbers.push_back(-1000000000000000ll);
numbers.push_back(-100000000000000ll);
numbers.push_back(-10000000000000ll);
numbers.push_back(-1000000000000ll);
numbers.push_back(-100000000000ll);
numbers.push_back(-10000000000ll);
numbers.push_back(-2147483649ll);
numbers.push_back(-1000000000000000000LL);
numbers.push_back(-100000000000000000LL);
numbers.push_back(-10000000000000000LL);
numbers.push_back(-1000000000000000LL);
numbers.push_back(-100000000000000LL);
numbers.push_back(-10000000000000LL);
numbers.push_back(-1000000000000LL);
numbers.push_back(-100000000000LL);
numbers.push_back(-10000000000LL);
numbers.push_back(-2147483649LL);
for (auto i : numbers)
{
CAPTURE(i)
@ -1610,7 +1610,7 @@ TEST_CASE("UBJSON")
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
json j;
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int, json::parse_event_t, const json&)
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
{
return true;
});

View File

@ -345,8 +345,8 @@ namespace udt
{
struct legacy_type
{
std::string number;
legacy_type() : number() {}
std::string number{};
legacy_type() = default;
legacy_type(std::string n) : number(std::move(n)) {}
};
} // namespace udt

View File

@ -60,7 +60,7 @@ const char* begin(const MyContainer& c)
const char* end(const MyContainer& c)
{
return c.data + strlen(c.data);
return c.data + strlen(c.data); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
}
TEST_CASE("Custom container non-member begin/end")
@ -88,7 +88,7 @@ TEST_CASE("Custom container member begin/end")
const char* end() const
{
return data + strlen(data);
return data + strlen(data); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
}
};
@ -114,7 +114,7 @@ TEST_CASE("Custom iterator")
MyIterator& operator++()
{
++ptr;
++ptr; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
return *this;
}
@ -139,7 +139,7 @@ TEST_CASE("Custom iterator")
CHECK(std::is_same<MyIterator::iterator_category, std::input_iterator_tag>::value);
MyIterator begin{raw_data};
MyIterator end{raw_data + strlen(raw_data)};
MyIterator end{raw_data + strlen(raw_data)}; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
json as_json = json::parse(begin, end);
CHECK(as_json.at(0) == 1);