[PATCH] D66397: [Diagnostics] Improve -Wxor-used-as-pow

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 21 11:58:26 PDT 2019


aaron.ballman added a comment.

In D66397#1639749 <https://reviews.llvm.org/D66397#1639749>, @thakis wrote:

> >> I think I missed the workaround. I only saw the suggestion to write 0x2 instead of 2 which doesn't seem more clear at all to me. Was there another fix suggestion?
> > 
> > Nope, you didn't miss it -- that was the suggestion. Using a hex notation is the way we let programmers signify that they want to do bit fiddling.
>
> Sorry, I don't buy that :) If I wasn't aware it's there to suppress a warning, if I saw `0x2` I'd think the author of that was confused about what the `0x` prefix does.


I don't understand how you draw that conclusion, but the reason behind why we went with that as a way to silence the diagnostic is because using the prefix acts as a signal that the developer wants to do bit manipulation more than just a decimal literal does. It's not ideal because it's largely a hidden way to silence diagnostics, but it's also not the only place where we do that sort of thing (like surrounding something in parens to silence a diagnostic, or casting something to void, etc).

> Maybe a better fixit is to suggest `xor` instead of `^` which also suppresses the warning and which is imho a bit less weird. (`xor` is so rare that it's still a bit weird though.)

I don't think suggesting a fixit for `xor` is a good solution. For starters, you need a header included in order to use that for C. As a textual suggestion "; use the 'xor' alternative token to perform an exclusive OR" wouldn't bother me too much though.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66397/new/

https://reviews.llvm.org/D66397





More information about the cfe-commits mailing list