Skip to content

Commit

Permalink
Merge pull request #1280 from nlohmann/feature/linter
Browse files Browse the repository at this point in the history
Removed linter warnings
  • Loading branch information
nlohmann authored Oct 8, 2018
2 parents ac38e95 + 6d34d64 commit adfa961
Show file tree
Hide file tree
Showing 29 changed files with 340 additions and 348 deletions.
2 changes: 1 addition & 1 deletion include/nlohmann/adl_serializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ struct adl_serializer
::nlohmann::to_json(j, std::forward<ValueType>(val));
}
};
}
} // namespace nlohmann
8 changes: 4 additions & 4 deletions include/nlohmann/detail/conversions/from_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ void from_json(const BasicJsonType& j, std::pair<A1, A2>& p)
}

template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence<Idx...>)
void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence<Idx...> /*unused*/)
{
t = std::make_tuple(j.at(Idx).template get<typename std::tuple_element<Idx, Tuple>::type>()...);
}
Expand Down Expand Up @@ -358,13 +358,13 @@ struct from_json_fn
return from_json(j, val);
}
};
}
} // namespace detail

/// namespace to hold default `from_json` function
/// to see why this is required:
/// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html
namespace
{
constexpr const auto& from_json = detail::static_const<detail::from_json_fn>::value;
}
}
} // namespace
} // namespace nlohmann
19 changes: 9 additions & 10 deletions include/nlohmann/detail/conversions/to_chars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ struct diyfp // f * 2^e
{
static constexpr int kPrecision = 64; // = q

uint64_t f;
int e;
uint64_t f = 0;
int e = 0;

constexpr diyfp() noexcept : f(0), e(0) {}
constexpr diyfp(uint64_t f_, int e_) noexcept : f(f_), e(e_) {}

/*!
Expand All @@ -62,7 +61,7 @@ struct diyfp // f * 2^e
assert(x.e == y.e);
assert(x.f >= y.f);

return diyfp(x.f - y.f, x.e);
return {x.f - y.f, x.e};
}

/*!
Expand Down Expand Up @@ -127,7 +126,7 @@ struct diyfp // f * 2^e

const uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32);

return diyfp(h, x.e + y.e + 64);
return {h, x.e + y.e + 64};
}

/*!
Expand Down Expand Up @@ -158,7 +157,7 @@ struct diyfp // f * 2^e
assert(delta >= 0);
assert(((x.f << delta) >> delta) == x.f);

return diyfp(x.f << delta, target_exponent);
return {x.f << delta, target_exponent};
}
};

Expand Down Expand Up @@ -461,7 +460,7 @@ inline cached_power get_cached_power_for_binary_exponent(int e)
assert(e >= -1500);
assert(e <= 1500);
const int f = kAlpha - e - 1;
const int k = (f * 78913) / (1 << 18) + (f > 0);
const int k = (f * 78913) / (1 << 18) + static_cast<int>(f > 0);

const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
assert(index >= 0);
Expand Down Expand Up @@ -609,7 +608,7 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent,

const diyfp one(uint64_t{1} << -M_plus.e, M_plus.e);

uint32_t p1 = static_cast<uint32_t>(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.)
auto p1 = static_cast<uint32_t>(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.)
uint64_t p2 = M_plus.f & (one.f - 1); // p2 = f mod 2^-e

// 1)
Expand Down Expand Up @@ -928,7 +927,7 @@ inline char* append_exponent(char* buf, int e)
*buf++ = '+';
}

uint32_t k = static_cast<uint32_t>(e);
auto k = static_cast<uint32_t>(e);
if (k < 10)
{
// Always print at least two digits in the exponent.
Expand Down Expand Up @@ -1046,7 +1045,7 @@ format. Returns an iterator pointing past-the-end of the decimal representation.
@note The result is NOT null-terminated.
*/
template <typename FloatType>
char* to_chars(char* first, char* last, FloatType value)
char* to_chars(char* first, const char* last, FloatType value)
{
static_cast<void>(last); // maybe unused - fix warning
assert(std::isfinite(value));
Expand Down
10 changes: 5 additions & 5 deletions include/nlohmann/detail/conversions/to_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,13 @@ void to_json(BasicJsonType& j, const std::pair<Args...>& p)
// for https://github.com/nlohmann/json/pull/1134
template<typename BasicJsonType, typename T,
enable_if_t<std::is_same<T, typename iteration_proxy<typename BasicJsonType::iterator>::iteration_proxy_internal>::value, int> = 0>
void to_json(BasicJsonType& j, T b) noexcept
void to_json(BasicJsonType& j, const T& b)
{
j = {{b.key(), b.value()}};
}

template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...>)
void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/)
{
j = {std::get<Idx>(t)...};
}
Expand All @@ -332,11 +332,11 @@ struct to_json_fn
return to_json(j, std::forward<T>(val));
}
};
}
} // namespace detail

/// namespace to hold default `to_json` function
namespace
{
constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value;
}
}
} // namespace
} // namespace nlohmann
4 changes: 2 additions & 2 deletions include/nlohmann/detail/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,5 +326,5 @@ class other_error : public exception
private:
other_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
};
}
}
} // namespace detail
} // namespace nlohmann
13 changes: 9 additions & 4 deletions include/nlohmann/detail/input/binary_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,20 @@ class binary_reader

case 0xF9: // Half-Precision Float (two-byte IEEE 754)
{
const int byte1 = get();
const int byte1_raw = get();
if (JSON_UNLIKELY(not unexpect_eof()))
{
return false;
}
const int byte2 = get();
const int byte2_raw = get();
if (JSON_UNLIKELY(not unexpect_eof()))
{
return false;
}

const auto byte1 = static_cast<unsigned char>(byte1_raw);
const auto byte2 = static_cast<unsigned char>(byte2_raw);

// code from RFC 7049, Appendix D, Figure 3:
// As half-precision floating-point numbers were only added
// to IEEE 754 in 2008, today's programming platforms often
Expand Down Expand Up @@ -1036,13 +1039,15 @@ class binary_reader
}

if (len != std::size_t(-1))
{
for (std::size_t i = 0; i < len; ++i)
{
if (JSON_UNLIKELY(not parse_cbor_internal()))
{
return false;
}
}
}
else
{
while (get() != 0xFF)
Expand Down Expand Up @@ -1693,5 +1698,5 @@ class binary_reader
/// the SAX parser
json_sax_t* sax = nullptr;
};
}
}
} // namespace detail
} // namespace nlohmann
15 changes: 10 additions & 5 deletions include/nlohmann/detail/input/input_adapters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class input_stream_adapter : public input_adapter_protocol
// delete because of pointer members
input_stream_adapter(const input_stream_adapter&) = delete;
input_stream_adapter& operator=(input_stream_adapter&) = delete;
input_stream_adapter(input_stream_adapter&&) = delete;
input_stream_adapter& operator=(input_stream_adapter&&) = delete;

// std::istream/std::streambuf use std::char_traits<char>::to_int_type, to
// ensure that std::char_traits<char>::eof() and the character 0xFF do not
Expand All @@ -97,6 +99,9 @@ class input_buffer_adapter : public input_adapter_protocol
// delete because of pointer members
input_buffer_adapter(const input_buffer_adapter&) = delete;
input_buffer_adapter& operator=(input_buffer_adapter&) = delete;
input_buffer_adapter(input_buffer_adapter&&) = delete;
input_buffer_adapter& operator=(input_buffer_adapter&&) = delete;
~input_buffer_adapter() override = default;

std::char_traits<char>::int_type get_character() noexcept override
{
Expand Down Expand Up @@ -131,7 +136,7 @@ struct wide_string_input_helper
else
{
// get the current character
const int wc = static_cast<int>(str[current_wchar++]);
const auto wc = static_cast<int>(str[current_wchar++]);

// UTF-32 to UTF-8 encoding
if (wc < 0x80)
Expand Down Expand Up @@ -186,7 +191,7 @@ struct wide_string_input_helper<WideStringType, 2>
else
{
// get the current character
const int wc = static_cast<int>(str[current_wchar++]);
const auto wc = static_cast<int>(str[current_wchar++]);

// UTF-16 to UTF-8 encoding
if (wc < 0x80)
Expand All @@ -211,7 +216,7 @@ struct wide_string_input_helper<WideStringType, 2>
{
if (current_wchar < str.size())
{
const int wc2 = static_cast<int>(str[current_wchar++]);
const auto wc2 = static_cast<int>(str[current_wchar++]);
const int charcode = 0x10000 + (((wc & 0x3FF) << 10) | (wc2 & 0x3FF));
utf8_bytes[0] = 0xf0 | (charcode >> 18);
utf8_bytes[1] = 0x80 | ((charcode >> 12) & 0x3F);
Expand Down Expand Up @@ -381,5 +386,5 @@ class input_adapter
/// the actual adapter
input_adapter_t ia = nullptr;
};
}
}
} // namespace detail
} // namespace nlohmann
Loading

0 comments on commit adfa961

Please sign in to comment.