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

refactor: Avoid unary minus on unsigned integers #1293

Closed
wants to merge 2 commits into from

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Apr 30, 2023

The assembly code remains unchanged.

In addition, this PR enables MSVC warning C4146 for the entire codebase.

@hebasto hebasto changed the title ci: Treat all compiler warnings as errors in "Windows (VS 2022)" task refactor: Avoid unary minus on unsigned integers Apr 30, 2023
@hebasto hebasto marked this pull request as draft April 30, 2023 17:22
@hebasto hebasto marked this pull request as ready for review April 30, 2023 17:35
@real-or-random
Copy link
Contributor

I think rewriting -x to (0 - x) is a bit nicer than `(~x + 1).

With that change applied, I think I'm literally ~0 on that PR: On the one hand, changing the code to make the compiler happy is not great... But perhaps having a clean build with just /W2 is good.

The assembly code remains unchanged.

In addition, this change enables MSVC warning C4146 for the entire
codebase.
See: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4146
@hebasto
Copy link
Member Author

hebasto commented May 2, 2023

I think rewriting -x to (0 - x) is a bit nicer than `(~x + 1).

Done.

On the one hand, changing the code to make the compiler happy is not great...

I agree with you.

But perhaps having a clean build with just /W2 is good.

That is my point.

Copy link
Contributor

@jonasnick jonasnick left a comment

Choose a reason for hiding this comment

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

Having to change perfectly fine -x to 0-x seems a bit annoying. I can imagine that this will confuse potential future reviewers. I don't think that's worth it.

@sipa
Copy link
Contributor

sipa commented May 11, 2023

Concept NACK, I think the resulting code is harder to read.

The warning in my opinion is silly (at least for our codebase), so the proper action is the disable the warning, not work around it.

@hebasto hebasto closed this May 11, 2023
@hebasto hebasto deleted the 230430-minus branch June 6, 2023 07: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.

None yet

4 participants