-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove conversion compiler warnings #844
Conversation
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<char>(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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove conversion compiler warnings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, just a few small comments.
include/fmt/format-inl.h
Outdated
@@ -374,7 +374,7 @@ FMT_FUNC char *write_exponent(char *buffer, int exp) { | |||
*buffer++ = '+'; | |||
} | |||
if (exp >= 100) { | |||
*buffer++ = '0' + static_cast<char>(exp / 100); | |||
*buffer++ = static_cast<char>('0' + static_cast<char>(exp / 100)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's enough to have only one (outer) static_cast.
include/fmt/format-inl.h
Outdated
@@ -384,7 +384,7 @@ FMT_FUNC char *write_exponent(char *buffer, int exp) { | |||
*buffer++ = d[0]; | |||
*buffer++ = d[1]; | |||
} else { | |||
*buffer++ = '0' + static_cast<char>(exp); | |||
*buffer++ = static_cast<char>('0' + static_cast<char>(exp)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
include/fmt/format-inl.h
Outdated
@@ -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<char>(digit); | |||
buffer[size++] = static_cast<char>('0' + static_cast<char>(digit)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
Merged, thanks! |
When compiling with g++8, I get the following two errors:
With this change, the errors are gone.