[cfe-commits] [Patch] Add new warning for logical not on LHS of comparison

Nico Weber thakis at chromium.org
Sat Oct 13 21:54:53 PDT 2012


On Sat, Oct 13, 2012 at 5:14 AM, Chris Lattner <clattner at apple.com> wrote:
>
> On Oct 12, 2012, at 11:10 AM, Richard Trieu <rtrieu at google.com> wrote:
>
> On Fri, Oct 12, 2012 at 9:55 AM, Sean Silva <silvas at purdue.edu> wrote:
>>
>> How many lines of code have you compiled with this warning enabled?
>
> Millions.
>>
>> How many bugs did it catch?
>
> Hundreds.
>>
>> How many false positives did it have?
>
> I have only checked a few dozen so far.  No false positives so far.
>
>
> This makes sense to me, use of a < comparison on a bool isn't something a
> "normal" person would write :)

I've seen bool < bool comparisons in operator< implementations (during
investigations for http://llvm.org/bugs/show_bug.cgi?id=13540 , which
is somewhat related to rtrieu's patch).

>
> -Chris
>
> Of course, there's some code like r165811 and r165812 that I just fixed,
> which technically works properly, but could be written in a different way.
>>
>>
>> -- Sean Silva
>>
>> On Fri, Oct 12, 2012 at 12:38 PM, Richard Trieu <rtrieu at google.com> wrote:
>> > This patch is for a new warning to Clang, called -Wlogical-not-compare.
>> > It
>> > is designed to catch the case where the user is attempting to negate a
>> > comparison, but only manages to negate the LHS because of missing
>> > parens.
>> > For instance, warn here:
>> >
>> >      if (!x < 5)
>> >
>> > The user probably meant:
>> >
>> >      if (!(x < 5))
>> >
>> > or
>> >
>> >      if (x >= 5)
>> >
>> > When emitted, the warning will have a note suggesting this as a fix-it
>> > (drop
>> > the not and inverting the comparison operator).
>> >
>> > Also, a second note will be offer parenthesis around the LHS to silence
>> > this
>> > warning.
>> >
>> >      if ((!x) < 5)
>> >
>> > This will not warn.
>> >
>> > _______________________________________________
>> > cfe-commits mailing list
>> > cfe-commits at cs.uiuc.edu
>> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>> >
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>



More information about the cfe-commits mailing list