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))

Attachment: bool-compare.patch
Description: Binary data

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to