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

Harald van Dijk via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun May 2 09:26:38 PDT 2021


hvdijk added a comment.

It's bad enough that this warns for

#define A 2
#define B 0
int f() { return A ^ B; }

where as far as the users of A are concerned, A is just some arbitrary value, it's just random chance it happens to be two and there is no chance of it being misinterpreted as exponentiation, but it's much worse that this cannot be worked around by changing the definition of A to 0x2, the only way to suppress the warning with a hexadecimal constant is by explicitly using that constant in the use, i.e. by changing the function to int f() { return 0x2 ^ B; }, which is very much inappropriate when the users of A are not supposed to care about which specific value it has.

I'd like to see this changed so that at least the #define A 0x2 case no longer triggers the warning, but ideally I'd like to see no warning for this example in its current state either. I see in the test case that that warning is intentional, but I'm not seeing from the previous discussion whether this case was based on real world programmer errors or not. Do you recall? If it was, then fair enough, I'll propose to leave that as it is.


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