Skip to content
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

Merged
merged 4 commits into from
Aug 29, 2018
Merged

Remove conversion compiler warnings #844

merged 4 commits into from
Aug 29, 2018

Conversation

medithe
Copy link
Contributor

@medithe medithe commented Aug 27, 2018

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.

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.
Copy link
Contributor Author

@medithe medithe left a 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

Copy link
Contributor

@vitaut vitaut left a 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.

@@ -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));
Copy link
Contributor

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.

@@ -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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@@ -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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

@vitaut vitaut merged commit 95a7189 into fmtlib:master Aug 29, 2018
@vitaut
Copy link
Contributor

vitaut commented Aug 29, 2018

Merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants