r183688 - Add a new warning, -Wlogical-not-parentheses, to -Wparentheses.

Sean McBride sean at rogue-research.com
Tue Jun 11 09:41:44 PDT 2013


I updated clang on my buildbot that builds the open source VTK project and it reported 4 unique -Wlogical-not-parentheses warnings:

I consider them to all be valid warnings either because the code really is wrong or could be made clearer anyway.

My (hopefully correct) patch for VTK:



On Mon, 10 Jun 2013 13:22:18 -0700, Nico Weber said:

>Do you have numbers on the true positive rate of this new warning (give
>that it's on by default)?
>On Mon, Jun 10, 2013 at 11:52 AM, Richard Trieu <rtrieu at google.com> wrote:
>> Author: rtrieu
>> Date: Mon Jun 10 13:52:07 2013
>> New Revision: 183688
>> URL: http://llvm.org/viewvc/llvm-project?rev=183688&view=rev
>> Log:
>> Add a new warning, -Wlogical-not-parentheses, to -Wparentheses.
>> This warning triggers on the logical not of a non-boolean expression on the
>> left hand side of comparison.  Often, the user meant to negate the
>> comparison,
>> not just the left hand side of the comparison.  Two notes are also emitted,
>> the first with a fix-it to add parentheses around the comparison, and the
>> other
>> to put parenthesis around the not expression to silence the warning.
>> bool not_equal(int x, int y) {
>>   return !x == y;  // warn here
>> }
>>   return !(x == y);  // first fix-it, to negate comparison.
>>   return (!x) == y;  // second fix-it, to silence warning.

More information about the cfe-commits mailing list