From 21acc2af43f7e259cc176ebbf869f29e225bec3d Mon Sep 17 00:00:00 2001 From: Ivan Shynkarenka Date: Wed, 23 Oct 2019 03:13:03 +0300 Subject: [PATCH] Fix more Visual Studio 2019 pedantic warnings (#1371) * format-inl.h(444,1): warning C4804: '>>': unsafe use of type 'bool' in operation format.h(2808,1): warning C4127: conditional expression is constant * More fixes for VS2019 pedantic warnings * Fix "conditional expression is constant" VS2019 warning in more specific way * Use const_check to silence constexpr warning --- include/fmt/format-inl.h | 5 ++--- include/fmt/format.h | 6 +++++- include/fmt/printf.h | 4 ---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 582c6193..5a789954 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -46,7 +46,6 @@ #ifdef _MSC_VER # pragma warning(push) -# pragma warning(disable : 4127) // conditional expression is constant # pragma warning(disable : 4702) // unreachable code #endif @@ -441,7 +440,7 @@ class fp { std::numeric_limits::digits - 1); if (min_normal_e > e) half_ulp <<= min_normal_e - e; upper = normalize<0>(fp(f + half_ulp, e)); - lower = fp(f - (half_ulp >> (f == implicit_bit && e > min_normal_e)), e); + lower = fp(f - (half_ulp >> ((f == implicit_bit && e > min_normal_e) ? 1 : 0)), e); lower.f <<= lower.e - upper.e; lower.e = upper.e; } @@ -939,7 +938,7 @@ template struct grisu_shortest_handler { uint64_t error, int exp, bool integral) { buf[size++] = digit; if (remainder >= error) return digits::more; - if (GRISU_VERSION != 3) { + if (const_check(GRISU_VERSION != 3)) { uint64_t d = integral ? diff : diff * data::powers_of_10_64[-exp]; round(d, divisor, remainder, error); return digits::done; diff --git a/include/fmt/format.h b/include/fmt/format.h index c359840e..43d40dc5 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -192,6 +192,10 @@ FMT_END_NAMESPACE FMT_BEGIN_NAMESPACE namespace internal { +// A helper function to suppress bogus "conditional expression is constant" +// warnings. +template inline T const_check(T value) { return value; } + // A fallback implementation of uintptr_t for systems that lack it. struct fallback_uintptr { unsigned char value[sizeof(void*)]; @@ -2807,7 +2811,7 @@ void internal::basic_writer::write_fp(T value, int precision = specs.precision >= 0 || !specs.type ? specs.precision : 6; unsigned options = 0; if (handler.fixed) options |= grisu_options::fixed; - if (sizeof(value) == sizeof(float)) options |= grisu_options::binary32; + if (const_check(sizeof(value) == sizeof(float))) options |= grisu_options::binary32; bool use_grisu = USE_GRISU && (specs.type != 'a' && specs.type != 'A' && specs.type != 'e' && diff --git a/include/fmt/printf.h b/include/fmt/printf.h index ced6b1b2..5b5f32ea 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -16,10 +16,6 @@ FMT_BEGIN_NAMESPACE namespace internal { -// A helper function to suppress bogus "conditional expression is constant" -// warnings. -template inline T const_check(T value) { return value; } - // Checks if a value fits in int - used to avoid warnings about comparing // signed and unsigned integers. template struct int_checker {