🚨 fix warnings

This commit is contained in:
Niels Lohmann 2021-09-04 22:36:43 +02:00
parent 6cf42d1b55
commit 526bee2bfb
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
3 changed files with 50 additions and 48 deletions

View File

@ -946,7 +946,7 @@ class binary_writer
case value_t::number_unsigned: case value_t::number_unsigned:
{ {
if (j.m_value.number_unsigned > (std::numeric_limits<std::int64_t>::max)()) if (j.m_value.number_unsigned > static_cast<typename BasicJsonType::number_unsigned_t>((std::numeric_limits<std::int64_t>::max)()))
{ {
JSON_THROW(out_of_range::create(407, "integer number " + std::to_string(j.m_value.number_unsigned) + " cannot be represented by BON8 as it does not fit int64", j)); JSON_THROW(out_of_range::create(407, "integer number " + std::to_string(j.m_value.number_unsigned) + " cannot be represented by BON8 as it does not fit int64", j));
} }
@ -1005,7 +1005,7 @@ class binary_writer
if (N <= 4) if (N <= 4)
{ {
// start array with count (80..84) // start array with count (80..84)
oa->write_character(to_char_type(0x80 + N)); oa->write_character(static_cast<std::uint8_t>(0x80 + N));
} }
else else
{ {
@ -1045,7 +1045,7 @@ class binary_writer
if (N <= 4) if (N <= 4)
{ {
// start object with count (86..8A) // start object with count (86..8A)
oa->write_character(to_char_type(0x86 + N)); oa->write_character(static_cast<std::uint8_t>(0x86 + N));
} }
else else
{ {
@ -1084,6 +1084,7 @@ class binary_writer
break; break;
} }
case value_t::binary:
case value_t::discarded: case value_t::discarded:
default: default:
break; break;
@ -1713,58 +1714,58 @@ class binary_writer
{ {
JSON_ASSERT(value >= -33554432); JSON_ASSERT(value >= -33554432);
value = -value - 1; value = -value - 1;
oa->write_character(to_char_type(0xF0 + (value >> 22 & 0x07))); oa->write_character(static_cast<std::uint8_t>(0xF0 + (value >> 22 & 0x07)));
oa->write_character(to_char_type(0xC0 + (value >> 16 & 0x3F))); oa->write_character(static_cast<std::uint8_t>(0xC0 + (value >> 16 & 0x3F)));
oa->write_character(to_char_type(value >> 8)); oa->write_character(static_cast<std::uint8_t>(value >> 8));
oa->write_character(to_char_type(value)); oa->write_character(static_cast<std::uint8_t>(value));
} }
else if (value < -1920) else if (value < -1920)
{ {
JSON_ASSERT(value >= -262144); JSON_ASSERT(value >= -262144);
value = -value - 1; value = -value - 1;
oa->write_character(to_char_type(0xE0 + (value >> 14 & 0x0F))); oa->write_character(static_cast<std::uint8_t>(0xE0 + (value >> 14 & 0x0F)));
oa->write_character(to_char_type(0xC0 + (value >> 8 & 0x3F))); oa->write_character(static_cast<std::uint8_t>(0xC0 + (value >> 8 & 0x3F)));
oa->write_character(to_char_type(value)); oa->write_character(static_cast<std::uint8_t>(value));
} }
else if (value < -10) else if (value < -10)
{ {
JSON_ASSERT(value >= -1920); JSON_ASSERT(value >= -1920);
value = -value - 1; value = -value - 1;
oa->write_character(to_char_type(0xC2 + (value >> 6 & 0x1F))); oa->write_character(static_cast<std::uint8_t>(0xC2 + (value >> 6 & 0x1F)));
oa->write_character(to_char_type(0xC0 + (value & 0x3F))); oa->write_character(static_cast<std::uint8_t>(0xC0 + (value & 0x3F)));
} }
else if (value < 0) else if (value < 0)
{ {
JSON_ASSERT(value >= -10); JSON_ASSERT(value >= -10);
value = -value - 1; value = -value - 1;
oa->write_character(to_char_type(0xB8 + value)); oa->write_character(static_cast<std::uint8_t>(0xB8 + value));
} }
else if (value <= 39) else if (value <= 39)
{ {
JSON_ASSERT(value >= 0); JSON_ASSERT(value >= 0);
oa->write_character(to_char_type(0x90 + value)); oa->write_character(static_cast<std::uint8_t>(0x90 + value));
} }
else if (value <= 3839) else if (value <= 3839)
{ {
JSON_ASSERT(value >= 0); JSON_ASSERT(value >= 0);
oa->write_character(to_char_type(0xC2 + (value >> 7 & 0x1F))); oa->write_character(static_cast<std::uint8_t>(0xC2 + (value >> 7 & 0x1F)));
oa->write_character(to_char_type(value & 0x7F)); oa->write_character(static_cast<std::uint8_t>(value & 0x7F));
} }
else if (value <= 524287) else if (value <= 524287)
{ {
JSON_ASSERT(value >= 0); JSON_ASSERT(value >= 0);
oa->write_character(to_char_type(0xE0 + (value >> 15 & 0x0F))); oa->write_character(static_cast<std::uint8_t>(0xE0 + (value >> 15 & 0x0F)));
oa->write_character(to_char_type(value >> 8 & 0x7F)); oa->write_character(static_cast<std::uint8_t>(value >> 8 & 0x7F));
oa->write_character(to_char_type(value)); oa->write_character(static_cast<std::uint8_t>(value));
} }
else else
{ {
JSON_ASSERT(value >= 0); JSON_ASSERT(value >= 0);
JSON_ASSERT(value <= 67108863); JSON_ASSERT(value <= 67108863);
oa->write_character(to_char_type(0xF0 + (value >> 23 & 0x17))); oa->write_character(static_cast<std::uint8_t>(0xF0 + (value >> 23 & 0x17)));
oa->write_character(to_char_type(value >> 16 & 0x7F)); oa->write_character(static_cast<std::uint8_t>(value >> 16 & 0x7F));
oa->write_character(to_char_type(value >> 8)); oa->write_character(static_cast<std::uint8_t>(value >> 8));
oa->write_character(to_char_type(value)); oa->write_character(static_cast<std::uint8_t>(value));
} }
} }

View File

@ -14520,7 +14520,7 @@ class binary_writer
case value_t::number_unsigned: case value_t::number_unsigned:
{ {
if (j.m_value.number_unsigned > (std::numeric_limits<std::int64_t>::max)()) if (j.m_value.number_unsigned > static_cast<typename BasicJsonType::number_unsigned_t>((std::numeric_limits<std::int64_t>::max)()))
{ {
JSON_THROW(out_of_range::create(407, "integer number " + std::to_string(j.m_value.number_unsigned) + " cannot be represented by BON8 as it does not fit int64", j)); JSON_THROW(out_of_range::create(407, "integer number " + std::to_string(j.m_value.number_unsigned) + " cannot be represented by BON8 as it does not fit int64", j));
} }
@ -14579,7 +14579,7 @@ class binary_writer
if (N <= 4) if (N <= 4)
{ {
// start array with count (80..84) // start array with count (80..84)
oa->write_character(to_char_type(0x80 + N)); oa->write_character(static_cast<std::uint8_t>(0x80 + N));
} }
else else
{ {
@ -14619,7 +14619,7 @@ class binary_writer
if (N <= 4) if (N <= 4)
{ {
// start object with count (86..8A) // start object with count (86..8A)
oa->write_character(to_char_type(0x86 + N)); oa->write_character(static_cast<std::uint8_t>(0x86 + N));
} }
else else
{ {
@ -14658,6 +14658,7 @@ class binary_writer
break; break;
} }
case value_t::binary:
case value_t::discarded: case value_t::discarded:
default: default:
break; break;
@ -15287,58 +15288,58 @@ class binary_writer
{ {
JSON_ASSERT(value >= -33554432); JSON_ASSERT(value >= -33554432);
value = -value - 1; value = -value - 1;
oa->write_character(to_char_type(0xF0 + (value >> 22 & 0x07))); oa->write_character(static_cast<std::uint8_t>(0xF0 + (value >> 22 & 0x07)));
oa->write_character(to_char_type(0xC0 + (value >> 16 & 0x3F))); oa->write_character(static_cast<std::uint8_t>(0xC0 + (value >> 16 & 0x3F)));
oa->write_character(to_char_type(value >> 8)); oa->write_character(static_cast<std::uint8_t>(value >> 8));
oa->write_character(to_char_type(value)); oa->write_character(static_cast<std::uint8_t>(value));
} }
else if (value < -1920) else if (value < -1920)
{ {
JSON_ASSERT(value >= -262144); JSON_ASSERT(value >= -262144);
value = -value - 1; value = -value - 1;
oa->write_character(to_char_type(0xE0 + (value >> 14 & 0x0F))); oa->write_character(static_cast<std::uint8_t>(0xE0 + (value >> 14 & 0x0F)));
oa->write_character(to_char_type(0xC0 + (value >> 8 & 0x3F))); oa->write_character(static_cast<std::uint8_t>(0xC0 + (value >> 8 & 0x3F)));
oa->write_character(to_char_type(value)); oa->write_character(static_cast<std::uint8_t>(value));
} }
else if (value < -10) else if (value < -10)
{ {
JSON_ASSERT(value >= -1920); JSON_ASSERT(value >= -1920);
value = -value - 1; value = -value - 1;
oa->write_character(to_char_type(0xC2 + (value >> 6 & 0x1F))); oa->write_character(static_cast<std::uint8_t>(0xC2 + (value >> 6 & 0x1F)));
oa->write_character(to_char_type(0xC0 + (value & 0x3F))); oa->write_character(static_cast<std::uint8_t>(0xC0 + (value & 0x3F)));
} }
else if (value < 0) else if (value < 0)
{ {
JSON_ASSERT(value >= -10); JSON_ASSERT(value >= -10);
value = -value - 1; value = -value - 1;
oa->write_character(to_char_type(0xB8 + value)); oa->write_character(static_cast<std::uint8_t>(0xB8 + value));
} }
else if (value <= 39) else if (value <= 39)
{ {
JSON_ASSERT(value >= 0); JSON_ASSERT(value >= 0);
oa->write_character(to_char_type(0x90 + value)); oa->write_character(static_cast<std::uint8_t>(0x90 + value));
} }
else if (value <= 3839) else if (value <= 3839)
{ {
JSON_ASSERT(value >= 0); JSON_ASSERT(value >= 0);
oa->write_character(to_char_type(0xC2 + (value >> 7 & 0x1F))); oa->write_character(static_cast<std::uint8_t>(0xC2 + (value >> 7 & 0x1F)));
oa->write_character(to_char_type(value & 0x7F)); oa->write_character(static_cast<std::uint8_t>(value & 0x7F));
} }
else if (value <= 524287) else if (value <= 524287)
{ {
JSON_ASSERT(value >= 0); JSON_ASSERT(value >= 0);
oa->write_character(to_char_type(0xE0 + (value >> 15 & 0x0F))); oa->write_character(static_cast<std::uint8_t>(0xE0 + (value >> 15 & 0x0F)));
oa->write_character(to_char_type(value >> 8 & 0x7F)); oa->write_character(static_cast<std::uint8_t>(value >> 8 & 0x7F));
oa->write_character(to_char_type(value)); oa->write_character(static_cast<std::uint8_t>(value));
} }
else else
{ {
JSON_ASSERT(value >= 0); JSON_ASSERT(value >= 0);
JSON_ASSERT(value <= 67108863); JSON_ASSERT(value <= 67108863);
oa->write_character(to_char_type(0xF0 + (value >> 23 & 0x17))); oa->write_character(static_cast<std::uint8_t>(0xF0 + (value >> 23 & 0x17)));
oa->write_character(to_char_type(value >> 16 & 0x7F)); oa->write_character(static_cast<std::uint8_t>(value >> 16 & 0x7F));
oa->write_character(to_char_type(value >> 8)); oa->write_character(static_cast<std::uint8_t>(value >> 8));
oa->write_character(to_char_type(value)); oa->write_character(static_cast<std::uint8_t>(value));
} }
} }

View File

@ -292,7 +292,7 @@ TEST_CASE("BON8")
SECTION("-2147483649") SECTION("-2147483649")
{ {
json j = -2147483649; json j = -2147483649L;
std::vector<uint8_t> expected = {0x8D, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF}; std::vector<uint8_t> expected = {0x8D, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF};
const auto result = json::to_bon8(j); const auto result = json::to_bon8(j);
CHECK(result == expected); CHECK(result == expected);
@ -303,7 +303,7 @@ TEST_CASE("BON8")
{ {
SECTION("-2147483648") SECTION("-2147483648")
{ {
json j = -2147483648; json j = -2147483648L;
std::vector<uint8_t> expected = {0x8C, 0x80, 0x00, 0x00, 0x00}; std::vector<uint8_t> expected = {0x8C, 0x80, 0x00, 0x00, 0x00};
const auto result = json::to_bon8(j); const auto result = json::to_bon8(j);
CHECK(result == expected); CHECK(result == expected);