Unverified Commit c5ee2229 authored by Niels Lohmann's avatar Niels Lohmann Committed by GitHub

Merge pull request #2211 from nlohmann/fix_warnings

Fix Clang-Tidy warnings
parents 635b9a0a a9809f33
Checks: '-*,
bugprone-*,
cert-*,
clang-analyzer-*,
google-*,
-google-runtime-references,
Checks: '*,
-cppcoreguidelines-avoid-goto,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-macro-usage,
-fuchsia-default-arguments-calls,
-fuchsia-default-arguments-declarations,
-fuchsia-overloaded-operator,
-google-explicit-constructor,
hicpp-*,
-google-runtime-references,
-hicpp-avoid-goto,
-hicpp-explicit-conversions,
-hicpp-no-array-decay,
-hicpp-uppercase-literal-suffix,
-hicpp-explicit-conversions,
misc-*,
-misc-non-private-member-variables-in-classes,
llvm-*,
-llvm-header-guard,
modernize-*,
-llvm-include-order,
-misc-non-private-member-variables-in-classes,
-modernize-use-trailing-return-type,
performance-*,
portability-*,
readability-*,
-readability-magic-numbers,
-readability-uppercase-literal-suffix'
......
......@@ -76,7 +76,7 @@ class input_stream_adapter
{
// clear stream flags; we use underlying streambuf I/O, do not
// maintain ifstream flags, except eof
if (is)
if (is != nullptr)
{
is->clear(is->rdstate() & std::ios::eofbit);
}
......@@ -411,7 +411,7 @@ template < typename CharT,
contiguous_bytes_input_adapter input_adapter(CharT b)
{
auto length = std::strlen(reinterpret_cast<const char*>(b));
auto ptr = reinterpret_cast<const char*>(b);
const auto* ptr = reinterpret_cast<const char*>(b);
return input_adapter(ptr, ptr + length);
}
......
......@@ -269,16 +269,16 @@ class json_sax_dom_parser
switch ((ex.id / 100) % 100)
{
case 1:
JSON_THROW(*static_cast<const detail::parse_error*>(&ex));
JSON_THROW(*dynamic_cast<const detail::parse_error*>(&ex));
case 4:
JSON_THROW(*static_cast<const detail::out_of_range*>(&ex));
JSON_THROW(*dynamic_cast<const detail::out_of_range*>(&ex));
// LCOV_EXCL_START
case 2:
JSON_THROW(*static_cast<const detail::invalid_iterator*>(&ex));
JSON_THROW(*dynamic_cast<const detail::invalid_iterator*>(&ex));
case 3:
JSON_THROW(*static_cast<const detail::type_error*>(&ex));
JSON_THROW(*dynamic_cast<const detail::type_error*>(&ex));
case 5:
JSON_THROW(*static_cast<const detail::other_error*>(&ex));
JSON_THROW(*dynamic_cast<const detail::other_error*>(&ex));
default:
assert(false);
// LCOV_EXCL_STOP
......@@ -523,16 +523,16 @@ class json_sax_dom_callback_parser
switch ((ex.id / 100) % 100)
{
case 1:
JSON_THROW(*static_cast<const detail::parse_error*>(&ex));
JSON_THROW(*dynamic_cast<const detail::parse_error*>(&ex));
case 4:
JSON_THROW(*static_cast<const detail::out_of_range*>(&ex));
JSON_THROW(*dynamic_cast<const detail::out_of_range*>(&ex));
// LCOV_EXCL_START
case 2:
JSON_THROW(*static_cast<const detail::invalid_iterator*>(&ex));
JSON_THROW(*dynamic_cast<const detail::invalid_iterator*>(&ex));
case 3:
JSON_THROW(*static_cast<const detail::type_error*>(&ex));
JSON_THROW(*dynamic_cast<const detail::type_error*>(&ex));
case 5:
JSON_THROW(*static_cast<const detail::other_error*>(&ex));
JSON_THROW(*dynamic_cast<const detail::other_error*>(&ex));
default:
assert(false);
// LCOV_EXCL_STOP
......
......@@ -131,7 +131,7 @@ class lexer : public lexer_base<BasicJsonType>
JSON_HEDLEY_PURE
static char get_decimal_point() noexcept
{
const auto loc = localeconv();
const auto* loc = localeconv();
assert(loc != nullptr);
return (loc->decimal_point == nullptr) ? '.' : *(loc->decimal_point);
}
......
......@@ -18,8 +18,6 @@ template<typename BasicJsonType> struct internal_iterator
typename BasicJsonType::object_t::iterator object_iterator {};
/// iterator for JSON arrays
typename BasicJsonType::array_t::iterator array_iterator {};
/// iterator for JSON binary arrays
typename BasicJsonType::binary_t::container_type::iterator binary_iterator {};
/// generic iterator for all other types
primitive_iterator_t primitive_iterator {};
};
......
......@@ -16,23 +16,30 @@ class json_ref
using value_type = BasicJsonType;
json_ref(value_type&& value)
: owned_value(std::move(value)), value_ref(&owned_value), is_rvalue(true)
: owned_value(std::move(value))
, value_ref(&owned_value)
, is_rvalue(true)
{}
json_ref(const value_type& value)
: value_ref(const_cast<value_type*>(&value)), is_rvalue(false)
: value_ref(const_cast<value_type*>(&value))
, is_rvalue(false)
{}
json_ref(std::initializer_list<json_ref> init)
: owned_value(init), value_ref(&owned_value), is_rvalue(true)
: owned_value(init)
, value_ref(&owned_value)
, is_rvalue(true)
{}
template <
class... Args,
enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 >
json_ref(Args && ... args)
: owned_value(std::forward<Args>(args)...), value_ref(&owned_value),
is_rvalue(true) {}
: owned_value(std::forward<Args>(args)...)
, value_ref(&owned_value)
, is_rvalue(true)
{}
// class should be movable only
json_ref(json_ref&&) = default;
......@@ -63,7 +70,7 @@ class json_ref
private:
mutable value_type owned_value = nullptr;
value_type* value_ref = nullptr;
const bool is_rvalue;
const bool is_rvalue = true;
};
} // namespace detail
} // namespace nlohmann
......@@ -573,7 +573,7 @@ class binary_writer
const auto N = j.m_value.binary->size();
if (N <= (std::numeric_limits<std::uint8_t>::max)())
{
std::uint8_t output_type;
std::uint8_t output_type{};
bool fixed = true;
if (use_ext)
{
......@@ -615,30 +615,18 @@ class binary_writer
}
else if (N <= (std::numeric_limits<std::uint16_t>::max)())
{
std::uint8_t output_type;
if (use_ext)
{
output_type = 0xC8; // ext 16
}
else
{
output_type = 0xC5; // bin 16
}
std::uint8_t output_type = use_ext
? 0xC8 // ext 16
: 0xC5; // bin 16
oa->write_character(to_char_type(output_type));
write_number(static_cast<std::uint16_t>(N));
}
else if (N <= (std::numeric_limits<std::uint32_t>::max)())
{
std::uint8_t output_type;
if (use_ext)
{
output_type = 0xC9; // ext 32
}
else
{
output_type = 0xC6; // bin 32
}
std::uint8_t output_type = use_ext
? 0xC9 // ext 32
: 0xC6; // bin 32
oa->write_character(to_char_type(output_type));
write_number(static_cast<std::uint32_t>(N));
......
......@@ -9,7 +9,7 @@
#include <cstdint> // uint8_t
#include <cstdio> // snprintf
#include <limits> // numeric_limits
#include <string> // string
#include <string> // string, char_traits
#include <type_traits> // is_same
#include <utility> // move
......@@ -59,8 +59,8 @@ class serializer
error_handler_t error_handler_ = error_handler_t::strict)
: o(std::move(s))
, loc(std::localeconv())
, thousands_sep(loc->thousands_sep == nullptr ? '\0' : * (loc->thousands_sep))
, decimal_point(loc->decimal_point == nullptr ? '\0' : * (loc->decimal_point))
, thousands_sep(loc->thousands_sep == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->thousands_sep)))
, decimal_point(loc->decimal_point == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->decimal_point)))
, indent_char(ichar)
, indent_string(512, indent_char)
, error_handler(error_handler_)
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment