Richard, do you have any more comments for this? I have a few style notes I could give, but I think this is really better for you or someone else more in Sema to look at.
Jordan
ping ....................................................................................................................... Per Viberg Senior Engineer Evidente ES East AB Warfvinges väg 34 SE-112 51 Stockholm Sweden This e-mail, which might contain confidential information, is addressed to the above stated person/company. If you are not the correct addressee, employee or in any other way the person concerned, please notify the sender immediately. At the same time, please delete this e-mail and destroy any prints. Thank You.
Från: Per Viberg Skickat: den 20 december 2013 14:47 Till: [email protected] Cc: Richard Trieu; Jordan Rose; Anders Rönnholm Ämne: SV: [PATCH] new check checking comparing of boolean expressions and literals
Hi, I agree with comments below from Richard Trieu. I found an existing check, DiagnoseOutOfRangeComparison in SemaChecking.cpp that was checking for always true/false expressions by range checking variables. It didn't find the special cases comparing boolean expressions with literals 1 and 0 though. Neither did it range check boolean expressions in C. I extended that check to detect always true/false cases of: C++: bool > 1: always false bool <= 1: always true bool < 0: always false bool >= 0: always true
0 <= bool: always true 0 > bool: always false 1 < bool: always false 1 >= bool: always true
C: boolean _expression_ > 1 or positive values: always false boolean _expression_ <= 1 or positive values: always true boolean _expression_ < 0 or negative values: always false boolean _expression_ >= 0 or negative values: always true
0 or negative values <= boolean _expression_: always true 0 or negative values > boolean _expression_: always false 1 or positive values < boolean _expression_: always false 1 or positive values >= boolean _expression_: always true
patch is attached. Best regards /Per ....................................................................................................................... Per Viberg Senior Engineer Evidente ES East AB Warfvinges väg 34 SE-112 51 Stockholm Sweden This e-mail, which might contain confidential information, is addressed to the above stated person/company. If you are not the correct addressee, employee or in any other way the person concerned, please notify the sender immediately. At the same time, please delete this e-mail and destroy any prints. Thank You.
Från: Richard Trieu [[email protected]] Skickat: den 12 november 2013 22:57 Till: Jordan Rose Cc: Per Viberg; [email protected] Ämne: Re: [PATCH] new check checking comparing of boolean expressions and literals
This warning should not be in -Wtautological-compare since not all cases always evaluate to the same value every time. For instance,
bool test(bool x) { return x > 0; }
This function can still return true or false. Check the other warnings in -Wtautological-compare which has their messages end with "always evaluates to " then some value. Otherwise, this warning basically boil down to users not writing code in the way we expected them to and then producing a vague warning. Possibly, split out the tautological parts to go into -Wtautological-compare, then add additional notes, maybe with fix-it hints, to help the user out.
|
relationalCompare_rev4_4.diff
Description: Binary data
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits