🚨 fix warnings

This commit is contained in:
Niels Lohmann 2021-01-28 16:38:11 +01:00
parent bdcabc05d1
commit 0dcb01bc47
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
9 changed files with 61 additions and 59 deletions

View File

@ -5,6 +5,7 @@ Checks: '*,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-pro-type-union-access,
-fuchsia-default-arguments-calls,
-fuchsia-default-arguments-declarations,
@ -26,6 +27,7 @@ Checks: '*,
-modernize-use-trailing-return-type,
-readability-function-size,
-readability-magic-numbers,
-readability-redundant-access-specifiers,
-readability-uppercase-literal-suffix,
-llvmlibc-*'

View File

@ -463,7 +463,7 @@ add_custom_target(ci_cppcheck
###############################################################################
add_custom_target(ci_cpplint
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/third_party/cpplint/cpplint.py --filter=-whitespace,-legal,-runtime/references,-runtime/explicit,-runtime/indentation_namespace,-readability/casting --quiet --recursive ${SRC_FILES}
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/third_party/cpplint/cpplint.py --filter=-whitespace,-legal,-runtime/references,-runtime/explicit,-runtime/indentation_namespace,-readability/casting,-readability/nolint --quiet --recursive ${SRC_FILES}
COMMENT "Check code with cpplint"
)

View File

@ -54,7 +54,7 @@ class exception : public std::exception
}
/// the id of the exception
const int id;
const int id; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes)
protected:
JSON_HEDLEY_NON_NULL(3)

View File

@ -78,9 +78,9 @@ class binary_reader
// make class move-only
binary_reader(const binary_reader&) = delete;
binary_reader(binary_reader&&) = default;
binary_reader(binary_reader&&) noexcept = default;
binary_reader& operator=(const binary_reader&) = delete;
binary_reader& operator=(binary_reader&&) = default;
binary_reader& operator=(binary_reader&&) noexcept = default;
~binary_reader() = default;
/*!
@ -315,7 +315,7 @@ class binary_reader
default: // anything else not supported (yet)
{
std::array<char, 3> cr{{}};
(std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type));
(std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type)); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
return sax->parse_error(element_type_parse_position, std::string(cr.data()), parse_error::create(114, element_type_parse_position, "Unsupported BSON record type 0x" + std::string(cr.data())));
}
}

View File

@ -166,9 +166,9 @@ class json_sax_dom_parser
// make class move-only
json_sax_dom_parser(const json_sax_dom_parser&) = delete;
json_sax_dom_parser(json_sax_dom_parser&&) = default;
json_sax_dom_parser(json_sax_dom_parser&&) noexcept = default;
json_sax_dom_parser& operator=(const json_sax_dom_parser&) = delete;
json_sax_dom_parser& operator=(json_sax_dom_parser&&) = default;
json_sax_dom_parser& operator=(json_sax_dom_parser&&) noexcept = default;
~json_sax_dom_parser() = default;
bool null()
@ -341,9 +341,9 @@ class json_sax_dom_callback_parser
// make class move-only
json_sax_dom_callback_parser(const json_sax_dom_callback_parser&) = delete;
json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) = default;
json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) noexcept = default;
json_sax_dom_callback_parser& operator=(const json_sax_dom_callback_parser&) = delete;
json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) = default;
json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) noexcept = default;
~json_sax_dom_callback_parser() = default;
bool null()

View File

@ -120,9 +120,9 @@ class lexer : public lexer_base<BasicJsonType>
// delete because of pointer members
lexer(const lexer&) = delete;
lexer(lexer&&) = default;
lexer(lexer&&) noexcept = default;
lexer& operator=(lexer&) = delete;
lexer& operator=(lexer&&) = default;
lexer& operator=(lexer&&) noexcept = default;
~lexer() = default;
private:

View File

@ -379,7 +379,7 @@ class serializer
*/
void dump_escaped(const string_t& s, const bool ensure_ascii)
{
std::uint32_t codepoint;
std::uint32_t codepoint{};
std::uint8_t state = UTF8_ACCEPT;
std::size_t bytes = 0; // number of bytes written to string_buffer
@ -700,12 +700,12 @@ class serializer
}
// use a pointer to fill the buffer
auto buffer_ptr = number_buffer.begin();
auto* buffer_ptr = number_buffer.begin();
const bool is_negative = std::is_same<NumberType, number_integer_t>::value && !(x >= 0); // see issue #755
number_unsigned_t abs_value;
unsigned int n_chars;
unsigned int n_chars{};
if (is_negative)
{
@ -805,8 +805,8 @@ class serializer
// erase thousands separator
if (thousands_sep != '\0')
{
const auto end = std::remove(number_buffer.begin(),
number_buffer.begin() + len, thousands_sep);
auto* const end = std::remove(number_buffer.begin(),
number_buffer.begin() + len, thousands_sep);
std::fill(end, number_buffer.end(), '\0');
JSON_ASSERT((end - number_buffer.begin()) <= len);
len = (end - number_buffer.begin());
@ -815,7 +815,7 @@ class serializer
// convert decimal point to '.'
if (decimal_point != '\0' && decimal_point != '.')
{
const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
auto* const dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
if (dec_pos != number_buffer.end())
{
*dec_pos = '.';

View File

@ -6201,7 +6201,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator==(const_reference lhs, const ScalarType rhs) noexcept
friend bool operator==(const_reference lhs, ScalarType rhs) noexcept
{
return lhs == basic_json(rhs);
}
@ -6212,7 +6212,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator==(const ScalarType lhs, const_reference rhs) noexcept
friend bool operator==(ScalarType lhs, const_reference rhs) noexcept
{
return basic_json(lhs) == rhs;
}
@ -6246,7 +6246,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator!=(const_reference lhs, const ScalarType rhs) noexcept
friend bool operator!=(const_reference lhs, ScalarType rhs) noexcept
{
return lhs != basic_json(rhs);
}
@ -6257,7 +6257,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator!=(const ScalarType lhs, const_reference rhs) noexcept
friend bool operator!=(ScalarType lhs, const_reference rhs) noexcept
{
return basic_json(lhs) != rhs;
}
@ -6367,7 +6367,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator<(const_reference lhs, const ScalarType rhs) noexcept
friend bool operator<(const_reference lhs, ScalarType rhs) noexcept
{
return lhs < basic_json(rhs);
}
@ -6378,7 +6378,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator<(const ScalarType lhs, const_reference rhs) noexcept
friend bool operator<(ScalarType lhs, const_reference rhs) noexcept
{
return basic_json(lhs) < rhs;
}
@ -6413,7 +6413,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator<=(const_reference lhs, const ScalarType rhs) noexcept
friend bool operator<=(const_reference lhs, ScalarType rhs) noexcept
{
return lhs <= basic_json(rhs);
}
@ -6424,7 +6424,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator<=(const ScalarType lhs, const_reference rhs) noexcept
friend bool operator<=(ScalarType lhs, const_reference rhs) noexcept
{
return basic_json(lhs) <= rhs;
}
@ -6459,7 +6459,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator>(const_reference lhs, const ScalarType rhs) noexcept
friend bool operator>(const_reference lhs, ScalarType rhs) noexcept
{
return lhs > basic_json(rhs);
}
@ -6470,7 +6470,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator>(const ScalarType lhs, const_reference rhs) noexcept
friend bool operator>(ScalarType lhs, const_reference rhs) noexcept
{
return basic_json(lhs) > rhs;
}
@ -6505,7 +6505,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator>=(const_reference lhs, const ScalarType rhs) noexcept
friend bool operator>=(const_reference lhs, ScalarType rhs) noexcept
{
return lhs >= basic_json(rhs);
}
@ -6516,7 +6516,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator>=(const ScalarType lhs, const_reference rhs) noexcept
friend bool operator>=(ScalarType lhs, const_reference rhs) noexcept
{
return basic_json(lhs) >= rhs;
}

View File

@ -2423,7 +2423,7 @@ class exception : public std::exception
}
/// the id of the exception
const int id;
const int id; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes)
protected:
JSON_HEDLEY_NON_NULL(3)
@ -3643,7 +3643,7 @@ void from_json(const BasicJsonType& j, std::valarray<T>& l)
}
template<typename BasicJsonType, typename T, std::size_t N>
auto from_json(const BasicJsonType& j, T (&arr)[N])
auto from_json(const BasicJsonType& j, T (&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
-> decltype(j.template get<T>(), void())
{
for (std::size_t i = 0; i < N; ++i)
@ -5453,9 +5453,9 @@ class json_sax_dom_parser
// make class move-only
json_sax_dom_parser(const json_sax_dom_parser&) = delete;
json_sax_dom_parser(json_sax_dom_parser&&) = default;
json_sax_dom_parser(json_sax_dom_parser&&) noexcept = default;
json_sax_dom_parser& operator=(const json_sax_dom_parser&) = delete;
json_sax_dom_parser& operator=(json_sax_dom_parser&&) = default;
json_sax_dom_parser& operator=(json_sax_dom_parser&&) noexcept = default;
~json_sax_dom_parser() = default;
bool null()
@ -5628,9 +5628,9 @@ class json_sax_dom_callback_parser
// make class move-only
json_sax_dom_callback_parser(const json_sax_dom_callback_parser&) = delete;
json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) = default;
json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) noexcept = default;
json_sax_dom_callback_parser& operator=(const json_sax_dom_callback_parser&) = delete;
json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) = default;
json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) noexcept = default;
~json_sax_dom_callback_parser() = default;
bool null()
@ -6107,9 +6107,9 @@ class lexer : public lexer_base<BasicJsonType>
// delete because of pointer members
lexer(const lexer&) = delete;
lexer(lexer&&) = default;
lexer(lexer&&) noexcept = default;
lexer& operator=(lexer&) = delete;
lexer& operator=(lexer&&) = default;
lexer& operator=(lexer&&) noexcept = default;
~lexer() = default;
private:
@ -7824,9 +7824,9 @@ class binary_reader
// make class move-only
binary_reader(const binary_reader&) = delete;
binary_reader(binary_reader&&) = default;
binary_reader(binary_reader&&) noexcept = default;
binary_reader& operator=(const binary_reader&) = delete;
binary_reader& operator=(binary_reader&&) = default;
binary_reader& operator=(binary_reader&&) noexcept = default;
~binary_reader() = default;
/*!
@ -8061,7 +8061,7 @@ class binary_reader
default: // anything else not supported (yet)
{
std::array<char, 3> cr{{}};
(std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type));
(std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type)); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
return sax->parse_error(element_type_parse_position, std::string(cr.data()), parse_error::create(114, element_type_parse_position, "Unsupported BSON record type 0x" + std::string(cr.data())));
}
}
@ -12671,7 +12671,7 @@ class json_ref
{}
// class should be movable only
json_ref(json_ref&&) = default;
json_ref(json_ref&&) noexcept = default;
json_ref(const json_ref&) = delete;
json_ref& operator=(const json_ref&) = delete;
json_ref& operator=(json_ref&&) = delete;
@ -15927,7 +15927,7 @@ class serializer
*/
void dump_escaped(const string_t& s, const bool ensure_ascii)
{
std::uint32_t codepoint;
std::uint32_t codepoint{};
std::uint8_t state = UTF8_ACCEPT;
std::size_t bytes = 0; // number of bytes written to string_buffer
@ -16248,12 +16248,12 @@ class serializer
}
// use a pointer to fill the buffer
auto buffer_ptr = number_buffer.begin();
auto* buffer_ptr = number_buffer.begin();
const bool is_negative = std::is_same<NumberType, number_integer_t>::value && !(x >= 0); // see issue #755
number_unsigned_t abs_value;
unsigned int n_chars;
unsigned int n_chars{};
if (is_negative)
{
@ -16353,8 +16353,8 @@ class serializer
// erase thousands separator
if (thousands_sep != '\0')
{
const auto end = std::remove(number_buffer.begin(),
number_buffer.begin() + len, thousands_sep);
auto* const end = std::remove(number_buffer.begin(),
number_buffer.begin() + len, thousands_sep);
std::fill(end, number_buffer.end(), '\0');
JSON_ASSERT((end - number_buffer.begin()) <= len);
len = (end - number_buffer.begin());
@ -16363,7 +16363,7 @@ class serializer
// convert decimal point to '.'
if (decimal_point != '\0' && decimal_point != '.')
{
const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
auto* const dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
if (dec_pos != number_buffer.end())
{
*dec_pos = '.';
@ -22822,7 +22822,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator==(const_reference lhs, const ScalarType rhs) noexcept
friend bool operator==(const_reference lhs, ScalarType rhs) noexcept
{
return lhs == basic_json(rhs);
}
@ -22833,7 +22833,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator==(const ScalarType lhs, const_reference rhs) noexcept
friend bool operator==(ScalarType lhs, const_reference rhs) noexcept
{
return basic_json(lhs) == rhs;
}
@ -22867,7 +22867,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator!=(const_reference lhs, const ScalarType rhs) noexcept
friend bool operator!=(const_reference lhs, ScalarType rhs) noexcept
{
return lhs != basic_json(rhs);
}
@ -22878,7 +22878,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator!=(const ScalarType lhs, const_reference rhs) noexcept
friend bool operator!=(ScalarType lhs, const_reference rhs) noexcept
{
return basic_json(lhs) != rhs;
}
@ -22988,7 +22988,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator<(const_reference lhs, const ScalarType rhs) noexcept
friend bool operator<(const_reference lhs, ScalarType rhs) noexcept
{
return lhs < basic_json(rhs);
}
@ -22999,7 +22999,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator<(const ScalarType lhs, const_reference rhs) noexcept
friend bool operator<(ScalarType lhs, const_reference rhs) noexcept
{
return basic_json(lhs) < rhs;
}
@ -23034,7 +23034,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator<=(const_reference lhs, const ScalarType rhs) noexcept
friend bool operator<=(const_reference lhs, ScalarType rhs) noexcept
{
return lhs <= basic_json(rhs);
}
@ -23045,7 +23045,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator<=(const ScalarType lhs, const_reference rhs) noexcept
friend bool operator<=(ScalarType lhs, const_reference rhs) noexcept
{
return basic_json(lhs) <= rhs;
}
@ -23080,7 +23080,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator>(const_reference lhs, const ScalarType rhs) noexcept
friend bool operator>(const_reference lhs, ScalarType rhs) noexcept
{
return lhs > basic_json(rhs);
}
@ -23091,7 +23091,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator>(const ScalarType lhs, const_reference rhs) noexcept
friend bool operator>(ScalarType lhs, const_reference rhs) noexcept
{
return basic_json(lhs) > rhs;
}
@ -23126,7 +23126,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator>=(const_reference lhs, const ScalarType rhs) noexcept
friend bool operator>=(const_reference lhs, ScalarType rhs) noexcept
{
return lhs >= basic_json(rhs);
}
@ -23137,7 +23137,7 @@ class basic_json
*/
template<typename ScalarType, typename std::enable_if<
std::is_scalar<ScalarType>::value, int>::type = 0>
friend bool operator>=(const ScalarType lhs, const_reference rhs) noexcept
friend bool operator>=(ScalarType lhs, const_reference rhs) noexcept
{
return basic_json(lhs) >= rhs;
}