This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/77292] value range propagation (VRP) would improve -Wlogical-not-parentheses
- From: "rguenth at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 19 Aug 2016 11:49:41 +0000
- Subject: [Bug c/77292] value range propagation (VRP) would improve -Wlogical-not-parentheses
- Authentication-results: sourceware.org; auth=none
- Auto-submitted: auto-generated
- References: <bug-77292-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77292
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to M Welinder from comment #3)
> The actual code I got this warning from was...
>
> if (!lower_tail == (p > phalf)) {
>
> where lower_tail is an int and p and phalf are doubles.
Well, that changes things because I agree that in the above case the
warning is bogus.
> That's simply a comparison of two booleans. Note, that the hinted-at code
>
> !(lower_tail == (p > phalf))
>
> is dubious: comparing an int to a booleans.
>
> > this isn't visible to the compiler when it analyzes
> > return !a == b;
>
> I am not aware of a rule that requires the compiler to ignore context
> when considering warnings. It certainly does consider context when
> it issues "might be used uninitialized" warnings, so why not here?
Because it's not done as in the frontend there is no data-flow available.
So, testcase:
int
foo (int a, int b)
{
return !a == (a < b);
}
t.c: In function ‘foo’:
t.c:4:13: warning: logical not is only applied to the left hand side of
comparison [-Wlogical-not-parentheses]
return !a == (a < b);
^~