From 22cfa65a3fb2e09c916a7f0924319e68fec60b37 Mon Sep 17 00:00:00 2001 From: medithe <40990424+medithe@users.noreply.github.com> Date: Mon, 27 Aug 2018 08:43:56 +0200 Subject: [PATCH 1/3] Remove conversion compiler warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When compiling with g++8, I get the following two errors: include/fmt/format-inl.h:400:29: error: conversion from ‘int’ to ‘char’ may change value [-Werror=conversion] buffer[size++] = zero + static_cast(digit); ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ include/fmt/format-inl.h:416:28: error: conversion from ‘int’ to ‘char’ may change value [-Werror=conversion] buffer[size++] = '0' + digit; ~~~~^~~~~~~ With this change, the errors are gone. --- include/fmt/format-inl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 98aaee269aca..ab4e65d58547 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -395,7 +395,7 @@ FMT_FUNC void grisu2_gen_digits( FMT_ASSERT(false, "invalid number of digits"); } if (digit != 0 || size != 0) - buffer[size++] = '0' + static_cast(digit); + buffer[size++] = static_cast('0' + static_cast(digit)); --kappa; uint64_t remainder = (static_cast(hi) << -one.e) + lo; if (remainder <= delta) { @@ -410,7 +410,7 @@ FMT_FUNC void grisu2_gen_digits( delta *= 10; char digit = static_cast(lo >> -one.e); if (digit != 0 || size != 0) - buffer[size++] = '0' + digit; + buffer[size++] = static_cast('0' + digit); lo &= one.f - 1; --kappa; if (lo < delta) { From d2741fd0e561bb62e141f602c38830b5b83ef63f Mon Sep 17 00:00:00 2001 From: medithe <40990424+medithe@users.noreply.github.com> Date: Tue, 28 Aug 2018 09:31:50 +0200 Subject: [PATCH 2/3] Update format-inl.h --- include/fmt/format-inl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index cd0213e718e6..825f4971bd4e 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -374,7 +374,7 @@ FMT_FUNC char *write_exponent(char *buffer, int exp) { *buffer++ = '+'; } if (exp >= 100) { - *buffer++ = '0' + static_cast(exp / 100); + *buffer++ = static_cast('0' + static_cast(exp / 100)); exp %= 100; const char *d = data::DIGITS + exp * 2; *buffer++ = d[0]; @@ -384,7 +384,7 @@ FMT_FUNC char *write_exponent(char *buffer, int exp) { *buffer++ = d[0]; *buffer++ = d[1]; } else { - *buffer++ = '0' + static_cast(exp); + *buffer++ = static_cast('0' + static_cast(exp)); } return buffer; } @@ -529,7 +529,7 @@ FMT_FUNC void grisu2_format(double value, char *buffer, size_t &size, char type, size_t unsigned_precision = precision >= 0 ? precision : 6; if (size > unsigned_precision) { // TODO: round instead of truncating - dec_exp += size - unsigned_precision; + dec_exp += static_cast(size - unsigned_precision); size = unsigned_precision; } grisu2_prettify(buffer, size, dec_exp, type, unsigned_precision, From 55fd7da2129392d99e2149e8cefa61695420de32 Mon Sep 17 00:00:00 2001 From: medithe <40990424+medithe@users.noreply.github.com> Date: Tue, 28 Aug 2018 17:23:03 +0200 Subject: [PATCH 3/3] Applied the proposed fixes from vitaut --- include/fmt/format-inl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 825f4971bd4e..c21b1b7a2dd7 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -374,7 +374,7 @@ FMT_FUNC char *write_exponent(char *buffer, int exp) { *buffer++ = '+'; } if (exp >= 100) { - *buffer++ = static_cast('0' + static_cast(exp / 100)); + *buffer++ = static_cast('0' + exp / 100); exp %= 100; const char *d = data::DIGITS + exp * 2; *buffer++ = d[0]; @@ -384,7 +384,7 @@ FMT_FUNC char *write_exponent(char *buffer, int exp) { *buffer++ = d[0]; *buffer++ = d[1]; } else { - *buffer++ = static_cast('0' + static_cast(exp)); + *buffer++ = static_cast('0' + exp); } return buffer; } @@ -421,7 +421,7 @@ FMT_FUNC void grisu2_gen_digits( FMT_ASSERT(false, "invalid number of digits"); } if (digit != 0 || size != 0) - buffer[size++] = static_cast('0' + static_cast(digit)); + buffer[size++] = static_cast('0' + digit); --exp; uint64_t remainder = (static_cast(hi) << -one.e) + lo; if (remainder <= delta) {