From 06f5573b02be4a281932c08f6c9adbc2b4745724 Mon Sep 17 00:00:00 2001 From: Benedek Thaler Date: Thu, 27 Feb 2020 16:06:18 +0100 Subject: [PATCH] Disable MSVC warning in integer_to_hex.hpp 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. --- include/mserialize/detail/integer_to_hex.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/mserialize/detail/integer_to_hex.hpp b/include/mserialize/detail/integer_to_hex.hpp index 5dda297..319e13d 100644 --- a/include/mserialize/detail/integer_to_hex.hpp +++ b/include/mserialize/detail/integer_to_hex.hpp @@ -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 constexpr char* write_integer_as_hex(Integer v, char* end) { @@ -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';