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

Clean-up sign-conversion warnings (rebased) #1440

Closed

Conversation

0x8000-0000
Copy link
Contributor

I agree that my contributions are licensed under the {fmt} license, and agree to future changes to the licensing.

This pull request contains the reviewed and agreed-upon portion of #1435, rebased on top of current master.

@0x8000-0000 0x8000-0000 changed the title No no sign conversion reviewed Clean-up sign-conversion warnings Dec 2, 2019
@0x8000-0000 0x8000-0000 changed the title Clean-up sign-conversion warnings Clean-up sign-conversion warnings (rebased) Dec 2, 2019
@0x8000-0000
Copy link
Contributor Author

What is a pull request

Welcome to GitHub - you might want to start with https://guides.github.com/activities/hello-world/

@fmtlib fmtlib deleted a comment from Danniiix Dec 2, 2019
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. As discussed in #1435, please keep the internal header include/fmt/format-inl.h as it is now i.e. revert the changes.

include/fmt/format.h Outdated Show resolved Hide resolved
include/fmt/printf.h Show resolved Hide resolved
Comment on lines 796 to 803
: context(ctx), out(o), val(d.count()), negative(false) {
if (d.count() < 0) {
val = 0 - val;
: context(ctx), out(o), val(static_cast<rep>(std::abs(d.count()))), negative(d.count() < 0) {

if (d.count() < 0) {
val = static_cast<rep>(- d.count());
negative = true;
}
}
else {
val = static_cast<rep>(d.count());
negative = false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There is too much redundancy here. Please keep the old code and just add a cast.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I apologize for the line 796, it was mismerged by me. I intended to remove the member initialization of val and negative.

But we can't keep the old code, since it assigns a possibly signed value "d.count()" into an unsigned variable "val". You need "val" to acquire the absolute value of d.count, which can be cleanly done either with "std::abs()" like on line 796, or with the test on 798:804.

Which one would you prefer?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should be enough to add static_cast to the initializer list.

test/scan.h Outdated Show resolved Hide resolved
@0x8000-0000
Copy link
Contributor Author

Thanks for the PR. As discussed in #1435, please keep the internal header include/fmt/format-inl.h as it is now i.e. revert the changes.

I will update as requested; this means I have to keep maintaining my fork that builds with -Wsign-conversion for a while, presumably until we get C++20 conformant compilers.

@vitaut
Copy link
Contributor

vitaut commented Dec 9, 2019

Merged with minor tweaks, thanks.

@vitaut vitaut closed this Dec 9, 2019
@0x8000-0000 0x8000-0000 deleted the no-no-sign-conversion-reviewed branch November 25, 2021 15:42
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