Skip to content

Commit

Permalink
Disable MSVC warning in integer_to_hex.hpp
Browse files Browse the repository at this point in the history
In a function template, MSVC complains about `unsigned -v`, but
the referenced line will be never reached if `v` is unsigned,
as `v > 0` will be always true.

Considered alternative: split write_integer_as_hex into two,
and call the correct overload via tag dispatching - but
this requires a lot of code duplication.
  • Loading branch information
BenedekThaler authored and erenon committed Feb 27, 2020
1 parent 0115922 commit 06f5573
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/mserialize/detail/integer_to_hex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ constexpr std::size_t hex_string_size(Integer v)
return size;
}

#ifdef _MSC_VER
// "unary minus operator applied to unsigned type, result still unsigned"
// The referenced line will be never reached if Integer is unsigned.
#pragma warning(push)
#pragma warning(disable : 4146)
#endif

template <typename Integer>
constexpr char* write_integer_as_hex(Integer v, char* end)
{
Expand Down Expand Up @@ -54,6 +61,10 @@ constexpr char* write_integer_as_hex(Integer v, char* end)
return end;
}

#ifdef _MSC_VER
#pragma warning(pop)
#endif

constexpr char* write_integer_as_hex(bool v, char* end)
{
*--end = v ? '1' : '0';
Expand Down

0 comments on commit 06f5573

Please sign in to comment.