A negation with ! is compared with a value that is not a truth value
What it finds
!x == y: ! binds tighter than ==, so this compares !x, which is 0 or 1, with y. Usually !(x == y), that is x != y, was meant.
Left alone are comparisons whose other side is a truth value too, or may be: !a == !b, !x == 0, !x == true, a comparison, a logical operation, a variable declared bool, and anything whose type the file does not show. So is !!x, which makes a truth value of x on purpose. Some code compares !x with an integer flag on purpose, which is why the rule is not in the default set.
From the rule's source, not_precedence.rs.
#include <stdbool.h> int test(int a, int b, bool flag, int mask){ int r = 0; if (!a == b)tx0 reports: !a is compared with ==, not the comparison negated r++; if (!(a & mask) != b)tx0 reports: !(a & mask) is compared with != r++; if (!a == !b) r++; if (!a == 0 || !a == 1) r++; if (!a == flag) r++; if (!!a == b) r++; if (!a == (b > 2)) r++; if (!a == unknown) r++; if (!(a == b)) r++; return r;} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/c:not-precedence" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/c:not-precedence] reason="..."tx0 explain tx0/c:not-precedence shows the same in the terminal. Found a false positive? Report it.