[PATCH] D63423: [Diagnostics] Diagnose misused xor as pow

Arthur O'Dwyer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun May 2 09:39:47 PDT 2021


Quuxplusone added a comment.

In D63423#2732152 <https://reviews.llvm.org/D63423#2732152>, @hvdijk wrote:

> It's bad enough that this warns for
>
> #define A 2
> int f() { return A ^ 1; }
>
> where as far as the users of A are concerned...

I see how this warning is arguably overzealous in the //very special case// of "raising" to the constant `1` (since nobody would ever write that by accident). However, if the user of A wants to indicate that they understand this is bitwise-xor, they can simply change the body of their `f` to `return A ^ 0x1;` — hex notation suppresses the warning.  (Changing the definition of `A` as well is perhaps a good idea but not technically required.)  IMO this is good enough and we should leave it.  (What do you think, having seen the `A ^ 0x1` workaround? Does that sufficiently address your needs?)

> [...] I'm not seeing from the previous discussion whether this case was based on real world programmer errors or not

The description links to a couple of tweets showing examples from the wild:
https://twitter.com/jfbastien/status/1139298419988549632
https://twitter.com/mikemx7f/status/1139335901790625793


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63423



More information about the cfe-commits mailing list