[cfe-commits] [Patch] Add new warning group and warnings for questionable boolean compares

Richard Trieu rtrieu at google.com
Fri Oct 26 17:20:49 PDT 2012


This patch is a proposal to add a new group of warnings under
-Wbool-compare.  The separate warnings are:

-Wbool-compare-logical-not
Comparisons of the form !x > y which usually means !(x < y) put is parsed
as (!x) < y.  Only checks if x is not boolean.  Suggests fixit.
High true positive rate.

-Wbool-compare-float
Comparison of float and bool.
High true positive rate.

-Wbool-compare-tautological
Comparisons involving a boolean and an expression evaluating to 1, 0, true,
or false such that the comparison always evaluate to true or false.
Also added to -Wtautological-compare group
High true positive rate.
Not previously caught by -Wtautological-compare

-Wbool-compare-tautological-out-of-range
Comparisons of a boolean and >1 or negative values.
Also added to -Wtautological-constant-out-of-range-compare group
High true positive rate.
Previously, only compares with values >1 were caught.
(x == 5)  currently caught
(x == -1)  not currently caught

-Wbool-compare-enum
Comparison of enum and bool.
Slightly lower true positive rates than the warnings above, but still over
90%.

-Wbool-compare-redundant
Comparisons where one of the operands and the operator could be dropped.
Includes fixit.
Default ignore.
More of a suggestion.
(x > 0)  ==>  (x)
(1 >= x) ==> (x)

-Wbool-compare-equivalent
Comparisons where the comparison is equivalent to negating one of the
operands.
Includes fixit.
Default ignore.
More of a suggestion.
(x != 1)  ==>  (!(x))
(0 == x)  ==>  (!(x))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121026/c671ffc0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bool-compare.patch
Type: application/octet-stream
Size: 27495 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121026/c671ffc0/attachment.obj>


More information about the cfe-commits mailing list