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
This commit is contained in:
Ivan Shynkarenka 2019-10-23 03:13:03 +03:00 committed by Victor Zverovich
parent 00669427df
commit 21acc2af43
3 changed files with 7 additions and 8 deletions

View File

@ -46,7 +46,6 @@
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning(push) # pragma warning(push)
# pragma warning(disable : 4127) // conditional expression is constant
# pragma warning(disable : 4702) // unreachable code # pragma warning(disable : 4702) // unreachable code
#endif #endif
@ -441,7 +440,7 @@ class fp {
std::numeric_limits<float>::digits - 1); std::numeric_limits<float>::digits - 1);
if (min_normal_e > e) half_ulp <<= min_normal_e - e; if (min_normal_e > e) half_ulp <<= min_normal_e - e;
upper = normalize<0>(fp(f + half_ulp, 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.f <<= lower.e - upper.e;
lower.e = upper.e; lower.e = upper.e;
} }
@ -939,7 +938,7 @@ template <int GRISU_VERSION> struct grisu_shortest_handler {
uint64_t error, int exp, bool integral) { uint64_t error, int exp, bool integral) {
buf[size++] = digit; buf[size++] = digit;
if (remainder >= error) return digits::more; 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]; uint64_t d = integral ? diff : diff * data::powers_of_10_64[-exp];
round(d, divisor, remainder, error); round(d, divisor, remainder, error);
return digits::done; return digits::done;

View File

@ -192,6 +192,10 @@ FMT_END_NAMESPACE
FMT_BEGIN_NAMESPACE FMT_BEGIN_NAMESPACE
namespace internal { namespace internal {
// A helper function to suppress bogus "conditional expression is constant"
// warnings.
template <typename T> inline T const_check(T value) { return value; }
// A fallback implementation of uintptr_t for systems that lack it. // A fallback implementation of uintptr_t for systems that lack it.
struct fallback_uintptr { struct fallback_uintptr {
unsigned char value[sizeof(void*)]; unsigned char value[sizeof(void*)];
@ -2807,7 +2811,7 @@ void internal::basic_writer<Range>::write_fp(T value,
int precision = specs.precision >= 0 || !specs.type ? specs.precision : 6; int precision = specs.precision >= 0 || !specs.type ? specs.precision : 6;
unsigned options = 0; unsigned options = 0;
if (handler.fixed) options |= grisu_options::fixed; 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 = bool use_grisu =
USE_GRISU && USE_GRISU &&
(specs.type != 'a' && specs.type != 'A' && specs.type != 'e' && (specs.type != 'a' && specs.type != 'A' && specs.type != 'e' &&

View File

@ -16,10 +16,6 @@
FMT_BEGIN_NAMESPACE FMT_BEGIN_NAMESPACE
namespace internal { namespace internal {
// A helper function to suppress bogus "conditional expression is constant"
// warnings.
template <typename T> inline T const_check(T value) { return value; }
// Checks if a value fits in int - used to avoid warnings about comparing // Checks if a value fits in int - used to avoid warnings about comparing
// signed and unsigned integers. // signed and unsigned integers.
template <bool IsSigned> struct int_checker { template <bool IsSigned> struct int_checker {