From 95a718992caa6386b0c53f1131d127e0fbfa1272 Mon Sep 17 00:00:00 2001 From: medithe <40990424+medithe@users.noreply.github.com> Date: Wed, 29 Aug 2018 15:38:56 +0200 Subject: [PATCH] Remove conversion compiler warnings (#844) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove conversion compiler warning 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 958a7b8f..c21b1b7a 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' + 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' + 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++] = '0' + static_cast(digit); + buffer[size++] = static_cast('0' + digit); --exp; uint64_t remainder = (static_cast(hi) << -one.e) + lo; if (remainder <= delta) { @@ -436,7 +436,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; --exp; if (lo < delta) { @@ -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,