🚨 removed compiler warnings

This commit is contained in:
Niels Lohmann 2018-06-23 10:28:04 +02:00
parent 0460b90977
commit 850922269d
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
5 changed files with 26 additions and 28 deletions

View file

@ -35,6 +35,7 @@ class binary_reader
{ {
using number_integer_t = typename BasicJsonType::number_integer_t; using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t; using string_t = typename BasicJsonType::string_t;
using json_sax_t = json_sax<BasicJsonType>; using json_sax_t = json_sax<BasicJsonType>;
@ -423,19 +424,21 @@ class binary_reader
val = (mant == 0) ? std::numeric_limits<double>::infinity() val = (mant == 0) ? std::numeric_limits<double>::infinity()
: std::numeric_limits<double>::quiet_NaN(); : std::numeric_limits<double>::quiet_NaN();
} }
return sax->number_float((half & 0x8000) != 0 ? -val : val, ""); return sax->number_float((half & 0x8000) != 0
? static_cast<number_float_t>(-val)
: static_cast<number_float_t>(val), "");
} }
case 0xFA: // Single-Precision Float (four-byte IEEE 754) case 0xFA: // Single-Precision Float (four-byte IEEE 754)
{ {
float number; float number;
return get_number(number) and sax->number_float(static_cast<double>(number), ""); return get_number(number) and sax->number_float(static_cast<number_float_t>(number), "");
} }
case 0xFB: // Double-Precision Float (eight-byte IEEE 754) case 0xFB: // Double-Precision Float (eight-byte IEEE 754)
{ {
double number; double number;
return get_number(number) and sax->number_float(number, ""); return get_number(number) and sax->number_float(static_cast<number_float_t>(number), "");
} }
default: // anything else (0xFF is handled inside the other types) default: // anything else (0xFF is handled inside the other types)
@ -676,13 +679,13 @@ class binary_reader
case 0xCA: // float 32 case 0xCA: // float 32
{ {
float number; float number;
return get_number(number) and sax->number_float(static_cast<double>(number), ""); return get_number(number) and sax->number_float(static_cast<number_float_t>(number), "");
} }
case 0xCB: // float 64 case 0xCB: // float 64
{ {
double number; double number;
return get_number(number) and sax->number_float(number, ""); return get_number(number) and sax->number_float(static_cast<number_float_t>(number), "");
} }
case 0xCC: // uint 8 case 0xCC: // uint 8
@ -1464,13 +1467,13 @@ class binary_reader
case 'd': case 'd':
{ {
float number; float number;
return get_number(number) and sax->number_float(static_cast<double>(number), ""); return get_number(number) and sax->number_float(static_cast<number_float_t>(number), "");
} }
case 'D': case 'D':
{ {
double number; double number;
return get_number(number) and sax->number_float(number, ""); return get_number(number) and sax->number_float(static_cast<number_float_t>(number), "");
} }
case 'C': // char case 'C': // char
@ -1664,7 +1667,7 @@ class binary_reader
std::string get_token_string() const std::string get_token_string() const
{ {
char cr[3]; char cr[3];
snprintf(cr, 3, "%.2X", current); snprintf(cr, 3, "%.2hhX", static_cast<unsigned char>(current));
return std::string{cr}; return std::string{cr};
} }

View file

@ -1173,7 +1173,7 @@ scan_number_done:
{ {
// escape control characters // escape control characters
char cs[9]; char cs[9];
snprintf(cs, 9, "<U+%.4X>", c); snprintf(cs, 9, "<U+%.4hhX>", c);
result += cs; result += cs;
} }
else else

View file

@ -3165,7 +3165,7 @@ scan_number_done:
{ {
// escape control characters // escape control characters
char cs[9]; char cs[9];
snprintf(cs, 9, "<U+%.4X>", c); snprintf(cs, 9, "<U+%.4hhX>", c);
result += cs; result += cs;
} }
else else
@ -5670,6 +5670,7 @@ class binary_reader
{ {
using number_integer_t = typename BasicJsonType::number_integer_t; using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t; using string_t = typename BasicJsonType::string_t;
using json_sax_t = json_sax<BasicJsonType>; using json_sax_t = json_sax<BasicJsonType>;
@ -6058,19 +6059,21 @@ class binary_reader
val = (mant == 0) ? std::numeric_limits<double>::infinity() val = (mant == 0) ? std::numeric_limits<double>::infinity()
: std::numeric_limits<double>::quiet_NaN(); : std::numeric_limits<double>::quiet_NaN();
} }
return sax->number_float((half & 0x8000) != 0 ? -val : val, ""); return sax->number_float((half & 0x8000) != 0
? static_cast<number_float_t>(-val)
: static_cast<number_float_t>(val), "");
} }
case 0xFA: // Single-Precision Float (four-byte IEEE 754) case 0xFA: // Single-Precision Float (four-byte IEEE 754)
{ {
float number; float number;
return get_number(number) and sax->number_float(static_cast<double>(number), ""); return get_number(number) and sax->number_float(static_cast<number_float_t>(number), "");
} }
case 0xFB: // Double-Precision Float (eight-byte IEEE 754) case 0xFB: // Double-Precision Float (eight-byte IEEE 754)
{ {
double number; double number;
return get_number(number) and sax->number_float(number, ""); return get_number(number) and sax->number_float(static_cast<number_float_t>(number), "");
} }
default: // anything else (0xFF is handled inside the other types) default: // anything else (0xFF is handled inside the other types)
@ -6311,13 +6314,13 @@ class binary_reader
case 0xCA: // float 32 case 0xCA: // float 32
{ {
float number; float number;
return get_number(number) and sax->number_float(static_cast<double>(number), ""); return get_number(number) and sax->number_float(static_cast<number_float_t>(number), "");
} }
case 0xCB: // float 64 case 0xCB: // float 64
{ {
double number; double number;
return get_number(number) and sax->number_float(number, ""); return get_number(number) and sax->number_float(static_cast<number_float_t>(number), "");
} }
case 0xCC: // uint 8 case 0xCC: // uint 8
@ -7099,13 +7102,13 @@ class binary_reader
case 'd': case 'd':
{ {
float number; float number;
return get_number(number) and sax->number_float(static_cast<double>(number), ""); return get_number(number) and sax->number_float(static_cast<number_float_t>(number), "");
} }
case 'D': case 'D':
{ {
double number; double number;
return get_number(number) and sax->number_float(number, ""); return get_number(number) and sax->number_float(static_cast<number_float_t>(number), "");
} }
case 'C': // char case 'C': // char
@ -7299,7 +7302,7 @@ class binary_reader
std::string get_token_string() const std::string get_token_string() const
{ {
char cr[3]; char cr[3];
snprintf(cr, 3, "%.2X", current); snprintf(cr, 3, "%.2hhX", static_cast<unsigned char>(current));
return std::string{cr}; return std::string{cr};
} }

View file

@ -40,14 +40,6 @@ using nlohmann::json;
#include <unordered_set> #include <unordered_set>
#include <valarray> #include <valarray>
namespace
{
template <typename MapType>
void map_type_conversion_checks()
{
}
}
TEST_CASE("value conversion") TEST_CASE("value conversion")
{ {
SECTION("get an object (explicit)") SECTION("get an object (explicit)")

View file

@ -1191,7 +1191,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
{ {
CAPTURE(filename); CAPTURE(filename);
std::ifstream f(filename); std::ifstream f(filename);
CHECK_THROWS_AS(json::parse(f), json::parse_error); CHECK_THROWS_AS(json::parse(f), json::parse_error&);
std::ifstream f2(filename); std::ifstream f2(filename);
CHECK(not json::accept(f2)); CHECK(not json::accept(f2));
} }
@ -1306,7 +1306,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
{ {
CAPTURE(filename); CAPTURE(filename);
std::ifstream f(filename); std::ifstream f(filename);
CHECK_THROWS_AS(json::parse(f), json::exception); // could be parse_error or out_of_range CHECK_THROWS_AS(json::parse(f), json::exception&); // could be parse_error or out_of_range
std::ifstream f2(filename); std::ifstream f2(filename);
CHECK(not json::accept(f2)); CHECK(not json::accept(f2));
} }