🚧 fixed more warnings
This commit is contained in:
parent
345a106d73
commit
8cec55a271
10 changed files with 82 additions and 30 deletions
22
Makefile
22
Makefile
|
@ -41,6 +41,28 @@ doctest:
|
|||
$(MAKE) check_output -C doc
|
||||
|
||||
|
||||
##########################################################################
|
||||
# warning detector
|
||||
##########################################################################
|
||||
|
||||
# calling Clang with all warnings, except:
|
||||
# -Wno-documentation-unknown-command: code uses user-defined commands like @complexity
|
||||
# -Wno-exit-time-destructors: warning in Catch code
|
||||
# -Wno-keyword-macro: unit-tests use "#define private public"
|
||||
# -Wno-deprecated-declarations: some functions are deprecated until 3.0.0
|
||||
# -Wno-range-loop-analysis: iterator_wrapper tests tests "for(const auto i...)"
|
||||
pedantic:
|
||||
$(MAKE) json_unit CXXFLAGS="\
|
||||
-std=c++11 \
|
||||
-Werror \
|
||||
-Weverything \
|
||||
-Wno-documentation-unknown-command \
|
||||
-Wno-exit-time-destructors \
|
||||
-Wno-keyword-macro \
|
||||
-Wno-deprecated-declarations \
|
||||
-Wno-range-loop-analysis"
|
||||
|
||||
|
||||
##########################################################################
|
||||
# fuzzing
|
||||
##########################################################################
|
||||
|
|
30
src/json.hpp
30
src/json.hpp
|
@ -673,7 +673,7 @@ template<typename BasicJsonType, typename UnscopedEnumType,
|
|||
enable_if_t<is_unscoped_enum<UnscopedEnumType>::value, int> = 0>
|
||||
void from_json(const BasicJsonType& j, UnscopedEnumType& e)
|
||||
{
|
||||
typename std::underlying_type<UnscopedEnumType>::type val = e;
|
||||
typename std::underlying_type<UnscopedEnumType>::type val;
|
||||
get_arithmetic_value(j, val);
|
||||
e = static_cast<UnscopedEnumType>(val);
|
||||
}
|
||||
|
@ -917,7 +917,7 @@ struct adl_serializer
|
|||
@ref basic_json class (either explicit or via conversion operators).
|
||||
|
||||
@param[in] j JSON value to read from
|
||||
@param[in, out] val value to write to
|
||||
@param[in,out] val value to write to
|
||||
*/
|
||||
template<typename BasicJsonType, typename ValueType>
|
||||
static void from_json(BasicJsonType&& j, ValueType& val) noexcept(
|
||||
|
@ -932,7 +932,7 @@ struct adl_serializer
|
|||
This function is usually called by the constructors of the @ref basic_json
|
||||
class.
|
||||
|
||||
@param[in, out] j JSON value to write to
|
||||
@param[in,out] j JSON value to write to
|
||||
@param[in] val value to read from
|
||||
*/
|
||||
template<typename BasicJsonType, typename ValueType>
|
||||
|
@ -6537,6 +6537,11 @@ class basic_json
|
|||
/// @{
|
||||
|
||||
private:
|
||||
/*!
|
||||
@note Some code in the switch cases has been copied, because otherwise
|
||||
copilers would complain about implicit fallthrough and there is no
|
||||
portable attribute to mute such warnings.
|
||||
*/
|
||||
template<typename T>
|
||||
static void add_to_vector(std::vector<uint8_t>& vec, size_t bytes, const T number)
|
||||
{
|
||||
|
@ -6550,20 +6555,27 @@ class basic_json
|
|||
vec.push_back(static_cast<uint8_t>((static_cast<uint64_t>(number) >> 060) & 0xff));
|
||||
vec.push_back(static_cast<uint8_t>((static_cast<uint64_t>(number) >> 050) & 0xff));
|
||||
vec.push_back(static_cast<uint8_t>((static_cast<uint64_t>(number) >> 040) & 0xff));
|
||||
// intentional fall-through
|
||||
vec.push_back(static_cast<uint8_t>((number >> 030) & 0xff));
|
||||
vec.push_back(static_cast<uint8_t>((number >> 020) & 0xff));
|
||||
vec.push_back(static_cast<uint8_t>((number >> 010) & 0xff));
|
||||
vec.push_back(static_cast<uint8_t>(number & 0xff));
|
||||
break;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
vec.push_back(static_cast<uint8_t>((number >> 030) & 0xff));
|
||||
vec.push_back(static_cast<uint8_t>((number >> 020) & 0xff));
|
||||
// intentional fall-through
|
||||
vec.push_back(static_cast<uint8_t>((number >> 010) & 0xff));
|
||||
vec.push_back(static_cast<uint8_t>(number & 0xff));
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
vec.push_back(static_cast<uint8_t>((number >> 010) & 0xff));
|
||||
// intentional fall-through
|
||||
vec.push_back(static_cast<uint8_t>(number & 0xff));
|
||||
break;
|
||||
}
|
||||
|
||||
case 1:
|
||||
|
@ -7865,7 +7877,9 @@ class basic_json
|
|||
}
|
||||
else
|
||||
{
|
||||
val = mant == 0 ? INFINITY : NAN;
|
||||
val = mant == 0
|
||||
? std::numeric_limits<double>::infinity()
|
||||
: std::numeric_limits<double>::quiet_NaN();
|
||||
}
|
||||
return (half & 0x8000) != 0 ? -val : val;
|
||||
}
|
||||
|
@ -11181,7 +11195,7 @@ basic_json_parser_74:
|
|||
// of characters determined by the lexer (len)
|
||||
const bool ok = (endptr == (data + len));
|
||||
|
||||
if (ok and (value == 0.0) and (*data == '-'))
|
||||
if (ok and (value == static_cast<T>(0.0)) and (*data == '-'))
|
||||
{
|
||||
// some implementations forget to negate the zero
|
||||
value = -0.0;
|
||||
|
|
|
@ -673,7 +673,7 @@ template<typename BasicJsonType, typename UnscopedEnumType,
|
|||
enable_if_t<is_unscoped_enum<UnscopedEnumType>::value, int> = 0>
|
||||
void from_json(const BasicJsonType& j, UnscopedEnumType& e)
|
||||
{
|
||||
typename std::underlying_type<UnscopedEnumType>::type val = e;
|
||||
typename std::underlying_type<UnscopedEnumType>::type val;
|
||||
get_arithmetic_value(j, val);
|
||||
e = static_cast<UnscopedEnumType>(val);
|
||||
}
|
||||
|
@ -917,7 +917,7 @@ struct adl_serializer
|
|||
@ref basic_json class (either explicit or via conversion operators).
|
||||
|
||||
@param[in] j JSON value to read from
|
||||
@param[in, out] val value to write to
|
||||
@param[in,out] val value to write to
|
||||
*/
|
||||
template<typename BasicJsonType, typename ValueType>
|
||||
static void from_json(BasicJsonType&& j, ValueType& val) noexcept(
|
||||
|
@ -932,7 +932,7 @@ struct adl_serializer
|
|||
This function is usually called by the constructors of the @ref basic_json
|
||||
class.
|
||||
|
||||
@param[in, out] j JSON value to write to
|
||||
@param[in,out] j JSON value to write to
|
||||
@param[in] val value to read from
|
||||
*/
|
||||
template<typename BasicJsonType, typename ValueType>
|
||||
|
@ -6537,6 +6537,11 @@ class basic_json
|
|||
/// @{
|
||||
|
||||
private:
|
||||
/*!
|
||||
@note Some code in the switch cases has been copied, because otherwise
|
||||
copilers would complain about implicit fallthrough and there is no
|
||||
portable attribute to mute such warnings.
|
||||
*/
|
||||
template<typename T>
|
||||
static void add_to_vector(std::vector<uint8_t>& vec, size_t bytes, const T number)
|
||||
{
|
||||
|
@ -6550,20 +6555,27 @@ class basic_json
|
|||
vec.push_back(static_cast<uint8_t>((static_cast<uint64_t>(number) >> 060) & 0xff));
|
||||
vec.push_back(static_cast<uint8_t>((static_cast<uint64_t>(number) >> 050) & 0xff));
|
||||
vec.push_back(static_cast<uint8_t>((static_cast<uint64_t>(number) >> 040) & 0xff));
|
||||
// intentional fall-through
|
||||
vec.push_back(static_cast<uint8_t>((number >> 030) & 0xff));
|
||||
vec.push_back(static_cast<uint8_t>((number >> 020) & 0xff));
|
||||
vec.push_back(static_cast<uint8_t>((number >> 010) & 0xff));
|
||||
vec.push_back(static_cast<uint8_t>(number & 0xff));
|
||||
break;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
vec.push_back(static_cast<uint8_t>((number >> 030) & 0xff));
|
||||
vec.push_back(static_cast<uint8_t>((number >> 020) & 0xff));
|
||||
// intentional fall-through
|
||||
vec.push_back(static_cast<uint8_t>((number >> 010) & 0xff));
|
||||
vec.push_back(static_cast<uint8_t>(number & 0xff));
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
vec.push_back(static_cast<uint8_t>((number >> 010) & 0xff));
|
||||
// intentional fall-through
|
||||
vec.push_back(static_cast<uint8_t>(number & 0xff));
|
||||
break;
|
||||
}
|
||||
|
||||
case 1:
|
||||
|
@ -7865,7 +7877,9 @@ class basic_json
|
|||
}
|
||||
else
|
||||
{
|
||||
val = mant == 0 ? INFINITY : NAN;
|
||||
val = mant == 0
|
||||
? std::numeric_limits<double>::infinity()
|
||||
: std::numeric_limits<double>::quiet_NaN();
|
||||
}
|
||||
return (half & 0x8000) != 0 ? -val : val;
|
||||
}
|
||||
|
@ -10215,7 +10229,7 @@ class basic_json
|
|||
// of characters determined by the lexer (len)
|
||||
const bool ok = (endptr == (data + len));
|
||||
|
||||
if (ok and (value == 0.0) and (*data == '-'))
|
||||
if (ok and (value == static_cast<T>(0.0)) and (*data == '-'))
|
||||
{
|
||||
// some implementations forget to negate the zero
|
||||
value = -0.0;
|
||||
|
|
|
@ -63,9 +63,9 @@ TEST_CASE("bad_alloc")
|
|||
}
|
||||
}
|
||||
|
||||
bool next_construct_fails = false;
|
||||
bool next_destroy_fails = false;
|
||||
bool next_deallocate_fails = false;
|
||||
static bool next_construct_fails = false;
|
||||
static bool next_destroy_fails = false;
|
||||
static bool next_deallocate_fails = false;
|
||||
|
||||
template<class T>
|
||||
struct my_allocator : std::allocator<T>
|
||||
|
|
|
@ -237,7 +237,7 @@ TEST_CASE("CBOR")
|
|||
const auto result = json::to_cbor(j);
|
||||
CHECK(result == expected);
|
||||
|
||||
int16_t restored = -1 - ((result[1] << 8) + result[2]);
|
||||
int16_t restored = static_cast<int16_t>(-1 - ((result[1] << 8) + result[2]));
|
||||
CHECK(restored == -9263);
|
||||
|
||||
// roundtrip
|
||||
|
|
|
@ -725,7 +725,7 @@ TEST_CASE("constructors")
|
|||
|
||||
SECTION("long double")
|
||||
{
|
||||
long double n = 42.23;
|
||||
long double n = 42.23l;
|
||||
json j(n);
|
||||
CHECK(j.type() == json::value_t::number_float);
|
||||
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
|
||||
|
|
|
@ -342,7 +342,7 @@ TEST_CASE("MessagePack")
|
|||
const auto result = json::to_msgpack(j);
|
||||
CHECK(result == expected);
|
||||
|
||||
int16_t restored = (result[1] << 8) + result[2];
|
||||
int16_t restored = static_cast<int16_t>((result[1] << 8) + result[2]);
|
||||
CHECK(restored == -9263);
|
||||
|
||||
// roundtrip
|
||||
|
@ -374,7 +374,7 @@ TEST_CASE("MessagePack")
|
|||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xd1);
|
||||
int16_t restored = (result[1] << 8) + result[2];
|
||||
int16_t restored = static_cast<int16_t>((result[1] << 8) + result[2]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
|
|
|
@ -163,7 +163,7 @@ TEST_CASE("README", "[hide]")
|
|||
j.clear(); // the array is empty again
|
||||
|
||||
// comparison
|
||||
j == "[\"foo\", 1, true]"_json; // true
|
||||
bool x = (j == "[\"foo\", 1, true]"_json); // true
|
||||
|
||||
// create an object
|
||||
json o;
|
||||
|
|
|
@ -350,8 +350,8 @@ TEST_CASE("regression tests")
|
|||
|
||||
// double
|
||||
nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, double> j_double =
|
||||
1.23e35f;
|
||||
CHECK(j_double.get<double>() == 1.23e35f);
|
||||
1.23e35;
|
||||
CHECK(j_double.get<double>() == 1.23e35);
|
||||
|
||||
// long double
|
||||
nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, long double>
|
||||
|
@ -641,7 +641,7 @@ TEST_CASE("regression tests")
|
|||
CHECK_THROWS_AS(json::from_msgpack(vec1), std::out_of_range);
|
||||
|
||||
// more test cases for MessagePack
|
||||
for (uint8_t b :
|
||||
for (auto b :
|
||||
{
|
||||
0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, // fixmap
|
||||
0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, // fixarray
|
||||
|
@ -649,12 +649,12 @@ TEST_CASE("regression tests")
|
|||
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf
|
||||
})
|
||||
{
|
||||
std::vector<uint8_t> vec(1, b);
|
||||
std::vector<uint8_t> vec(1, static_cast<uint8_t>(b));
|
||||
CHECK_THROWS_AS(json::from_msgpack(vec), std::out_of_range);
|
||||
}
|
||||
|
||||
// more test cases for CBOR
|
||||
for (uint8_t b :
|
||||
for (auto b :
|
||||
{
|
||||
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, // UTF-8 string
|
||||
|
@ -664,7 +664,7 @@ TEST_CASE("regression tests")
|
|||
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7 // map
|
||||
})
|
||||
{
|
||||
std::vector<uint8_t> vec(1, b);
|
||||
std::vector<uint8_t> vec(1, static_cast<uint8_t>(b));
|
||||
CHECK_THROWS_AS(json::from_cbor(vec), std::out_of_range);
|
||||
}
|
||||
|
||||
|
|
|
@ -816,6 +816,8 @@ TEST_CASE("nst's JSONTestSuite")
|
|||
}
|
||||
}
|
||||
|
||||
std::string trim(const std::string& str);
|
||||
|
||||
// from http://stackoverflow.com/a/25829178/266378
|
||||
std::string trim(const std::string& str)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue