From 5aa1b4d92a1698da7bcdcc954ac61b778095f35e Mon Sep 17 00:00:00 2001 From: Ivan Shynkarenka Date: Mon, 21 Oct 2019 11:28:06 +0300 Subject: [PATCH 1/5] format-inl.h(444,1): warning C4804: '>>': unsafe use of type 'bool' in operation format.h(2808,1): warning C4127: conditional expression is constant --- include/fmt/format-inl.h | 2 +- include/fmt/format.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 582c61933cfa..fb4b4b1c90d0 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -441,7 +441,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; } diff --git a/include/fmt/format.h b/include/fmt/format.h index 9ca0be1892ff..5ff4c86fb099 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2805,7 +2805,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 constexpr (sizeof(value) == sizeof(float)) options |= grisu_options::binary32; bool use_grisu = USE_GRISU && (specs.type != 'a' && specs.type != 'A' && specs.type != 'e' && From 55b42e8f4a6c3121f996e7d2a70a9621fa7f7f06 Mon Sep 17 00:00:00 2001 From: Ivan Shynkarenka Date: Mon, 21 Oct 2019 11:37:10 +0300 Subject: [PATCH 2/5] More fixes for VS2019 pedantic warnings --- include/fmt/format.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 5ff4c86fb099..16371afbc2d7 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -71,6 +71,11 @@ # define FMT_HAS_BUILTIN(x) 0 #endif +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable : 4127) // conditional expression is constant +#endif + #ifndef FMT_THROW # if FMT_EXCEPTIONS # if FMT_MSC_VER @@ -2805,7 +2810,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 constexpr (sizeof(value) == sizeof(float)) options |= grisu_options::binary32; + if (sizeof(value) == sizeof(float)) options |= grisu_options::binary32; bool use_grisu = USE_GRISU && (specs.type != 'a' && specs.type != 'A' && specs.type != 'e' && @@ -3577,6 +3582,10 @@ FMT_CONSTEXPR internal::udl_arg operator"" _a(const wchar_t* s, #endif // FMT_USE_USER_DEFINED_LITERALS FMT_END_NAMESPACE +#ifdef _MSC_VER +# pragma warning(pop) +#endif + /** \rst Constructs a compile-time format string. From ee339bcfa3cbb41438b21716bc18cd0a6c7b504a Mon Sep 17 00:00:00 2001 From: Ivan Shynkarenka Date: Mon, 21 Oct 2019 17:13:16 +0300 Subject: [PATCH 3/5] Fix "conditional expression is constant" VS2019 warning in more specific way --- include/fmt/format-inl.h | 5 ++++- include/fmt/format.h | 13 ++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index fb4b4b1c90d0..49bb77f08018 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 @@ -939,7 +938,11 @@ template struct grisu_shortest_handler { uint64_t error, int exp, bool integral) { buf[size++] = digit; if (remainder >= error) return digits::more; +#ifdef __cpp_if_constexpr + if constexpr (GRISU_VERSION != 3) { +#else if (GRISU_VERSION != 3) { +#endif 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 16371afbc2d7..762546534d19 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -71,11 +71,6 @@ # define FMT_HAS_BUILTIN(x) 0 #endif -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable : 4127) // conditional expression is constant -#endif - #ifndef FMT_THROW # if FMT_EXCEPTIONS # if FMT_MSC_VER @@ -2810,7 +2805,11 @@ 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; +#ifdef __cpp_if_constexpr + if constexpr (sizeof(value) == sizeof(float)) options |= grisu_options::binary32; +#else if (sizeof(value) == sizeof(float)) options |= grisu_options::binary32; +#endif bool use_grisu = USE_GRISU && (specs.type != 'a' && specs.type != 'A' && specs.type != 'e' && @@ -3582,10 +3581,6 @@ FMT_CONSTEXPR internal::udl_arg operator"" _a(const wchar_t* s, #endif // FMT_USE_USER_DEFINED_LITERALS FMT_END_NAMESPACE -#ifdef _MSC_VER -# pragma warning(pop) -#endif - /** \rst Constructs a compile-time format string. From 313c48baff1fe27c26e8c863e8efbc1826ffa627 Mon Sep 17 00:00:00 2001 From: Ivan Shynkarenka Date: Tue, 22 Oct 2019 11:32:06 +0300 Subject: [PATCH 4/5] Use const_check to silence constexpr warning --- include/fmt/format-inl.h | 6 +----- include/fmt/format.h | 4 ++++ include/fmt/printf.h | 4 ---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 49bb77f08018..5a789954a1c5 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -938,11 +938,7 @@ template struct grisu_shortest_handler { uint64_t error, int exp, bool integral) { buf[size++] = digit; if (remainder >= error) return digits::more; -#ifdef __cpp_if_constexpr - if constexpr (GRISU_VERSION != 3) { -#else - if (GRISU_VERSION != 3) { -#endif + 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 762546534d19..14cce7274a9a 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*)]; diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 8be33b994fa4..e48c59033160 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 { From 2dc58f1b609ba43241b6c7a68dcd37fdb67e8c2a Mon Sep 17 00:00:00 2001 From: Ivan Shynkarenka Date: Tue, 22 Oct 2019 18:45:22 +0300 Subject: [PATCH 5/5] Use const_check to silence constexpr warning --- include/fmt/format.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 14cce7274a9a..c505520b1b35 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2809,11 +2809,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; -#ifdef __cpp_if_constexpr - if constexpr (sizeof(value) == sizeof(float)) options |= grisu_options::binary32; -#else - if (sizeof(value) == sizeof(float)) options |= grisu_options::binary32; -#endif + 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' &&