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