Skip to content

Commit

Permalink
fixed issue #239 (-Wconversion warnings)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed May 11, 2016
2 parents 9ecf83f + 91aa4c9 commit db5c9ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,15 +757,15 @@ class basic_json
/// assignment
type_data_t& operator=(value_t rhs)
{
bits.type = static_cast<uint16_t>(rhs);
bits.type = static_cast<uint16_t>(rhs) & 15; // avoid overflow
return *this;
}

/// construct from value_t
type_data_t(value_t t) noexcept
{
*reinterpret_cast<uint16_t*>(this) = 0;
bits.type = static_cast<uint16_t>(t);
bits.type = static_cast<uint16_t>(t) & 15; // avoid overflow
}

/// default constructor
Expand Down Expand Up @@ -6011,9 +6011,11 @@ class basic_json
{
// convert a number 0..15 to its hex representation
// (0..f)
auto hexify = [](const char v) -> char
const auto hexify = [](const int v) -> char
{
return (v < 10) ? ('0' + v) : ('a' + v - 10);
return (v < 10)
? ('0' + static_cast<char>(v))
: ('a' + static_cast<char>((v - 10) & 0x1f));
};

// print character c as \uxxxx
Expand Down
10 changes: 6 additions & 4 deletions src/json.hpp.re2c
Original file line number Diff line number Diff line change
Expand Up @@ -757,15 +757,15 @@ class basic_json
/// assignment
type_data_t& operator=(value_t rhs)
{
bits.type = static_cast<uint16_t>(rhs);
bits.type = static_cast<uint16_t>(rhs) & 15; // avoid overflow
return *this;
}

/// construct from value_t
type_data_t(value_t t) noexcept
{
*reinterpret_cast<uint16_t*>(this) = 0;
bits.type = static_cast<uint16_t>(t);
bits.type = static_cast<uint16_t>(t) & 15; // avoid overflow
}

/// default constructor
Expand Down Expand Up @@ -6011,9 +6011,11 @@ class basic_json
{
// convert a number 0..15 to its hex representation
// (0..f)
auto hexify = [](const char v) -> char
const auto hexify = [](const int v) -> char
{
return (v < 10) ? ('0' + v) : ('a' + v - 10);
return (v < 10)
? ('0' + static_cast<char>(v))
: ('a' + static_cast<char>((v - 10) & 0x1f));
};

// print character c as \uxxxx
Expand Down

0 comments on commit db5c9ec

Please sign in to comment.