mirror of
https://github.com/nlohmann/json.git
synced 2026-10-12 01:17:14 +00:00
Fix CI warnings in own float parser
- pow5_table.hpp: pow5_128_largest_power was unused in this branch's own code (GCC -Werror=unused-const-variable); tie it to the table size with a static_assert instead of removing it, since a later branch in the stack (json-view/23-zmij) uses it. - number_parse.hpp: rename the local variable `copy` to `buffer` to satisfy cpplint's build/include_what_you_use check. - unit-class_lexer.cpp: extend the NOLINT list on the seeded mt19937 with bugprone-random-generator-seed, and parenthesize `8 * sizeof(Bits) - 1` for clang-tidy. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
3 files changed
+10
-6
No files matched your search
@@ -987,10 +987,10 @@ void convert_float_locale_aware(StringType& token, std::size_t decimal_point_pos
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::string copy(token.data(), token.size());
|
std::string buffer(token.data(), token.size());
|
||||||
copy.replace(decimal_point_position, 1, decimal_point);
|
buffer.replace(decimal_point_position, 1, decimal_point);
|
||||||
strtof_by_type(value, copy.c_str(), &endptr);
|
strtof_by_type(value, buffer.c_str(), &endptr);
|
||||||
complete = endptr == copy.c_str() + copy.size();
|
complete = endptr == buffer.c_str() + buffer.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (JSON_HEDLEY_LIKELY(complete))
|
if (JSON_HEDLEY_LIKELY(complete))
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ namespace detail
|
|||||||
constexpr std::int64_t pow5_128_smallest_power = -342;
|
constexpr std::int64_t pow5_128_smallest_power = -342;
|
||||||
constexpr std::int64_t pow5_128_largest_power = 308;
|
constexpr std::int64_t pow5_128_largest_power = 308;
|
||||||
|
|
||||||
|
// every entry of pow5_128() holds two 64-bit halves of 5^q, one per covered power of 5
|
||||||
|
static_assert((pow5_128_largest_power - pow5_128_smallest_power + 1) * 2 == 1302,
|
||||||
|
"pow5_128_smallest_power/pow5_128_largest_power must match the size of the pow5_128() table");
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief 128-bit approximations of 5^q for q in [-342, 308]
|
@brief 128-bit approximations of 5^q for q in [-342, 308]
|
||||||
|
|
||||||
|
|||||||
@@ -802,7 +802,7 @@ TEST_CASE("lexer escape fast path")
|
|||||||
// digits and non-hex bytes, at varying distances from the start of
|
// digits and non-hex bytes, at varying distances from the start of
|
||||||
// the string, to compare the two scanners on many more shapes than
|
// the string, to compare the two scanners on many more shapes than
|
||||||
// are practical to enumerate by hand.
|
// are practical to enumerate by hand.
|
||||||
std::mt19937 gen(7654321); // NOLINT(cert-msc32-c,cert-msc51-cpp)
|
std::mt19937 gen(7654321); // NOLINT(cert-msc32-c,cert-msc51-cpp,bugprone-random-generator-seed)
|
||||||
const std::string hex_alphabet = "0123456789AaBbCcDdEeFf";
|
const std::string hex_alphabet = "0123456789AaBbCcDdEeFf";
|
||||||
std::uniform_int_distribution<std::size_t> pick_hex(0, hex_alphabet.size() - 1);
|
std::uniform_int_distribution<std::size_t> pick_hex(0, hex_alphabet.size() - 1);
|
||||||
std::uniform_int_distribution<int> pick_byte(1, 255); // never NUL
|
std::uniform_int_distribution<int> pick_byte(1, 255); // never NUL
|
||||||
@@ -1630,7 +1630,7 @@ template<typename Json, typename Bits>
|
|||||||
void check_parse(const std::string& token, Bits expected, Bits infinity)
|
void check_parse(const std::string& token, Bits expected, Bits infinity)
|
||||||
{
|
{
|
||||||
std::stringstream stream(token);
|
std::stringstream stream(token);
|
||||||
if ((expected & ~(Bits{1} << (8 * sizeof(Bits) - 1))) == infinity)
|
if ((expected & ~(Bits{1} << ((8 * sizeof(Bits)) - 1))) == infinity)
|
||||||
{
|
{
|
||||||
Json _;
|
Json _;
|
||||||
CHECK_THROWS_WITH_AS(_ = Json::parse(token), ("[json.exception.out_of_range.406] number overflow parsing '" + token + "'").c_str(), typename Json::out_of_range&);
|
CHECK_THROWS_WITH_AS(_ = Json::parse(token), ("[json.exception.out_of_range.406] number overflow parsing '" + token + "'").c_str(), typename Json::out_of_range&);
|
||||||
|
|||||||
Reference in new issue
Block a user