Both operands of an operator are the same
What it finds
a == a, n - n, x && x: an operator whose operands are the same expression gives a result known in advance, or the operand itself, and one of the two operands was usually meant to be something else, as in a.x == a.x for a.x == b.x.
For floating-point values x != x tests for NaN and x - x can be NaN, so the rule needs to know the types: every name in the operands must be declared in the file with a type that is an integer, an enum or a pointer, as far as [crate::types] can tell, and not volatile, since reading a volatile object twice can give two values. No operand may hold a call, which may be a macro, a cast or a floating literal, and expressions given to a macro or inside sizeof are left alone. Operands made of constants alone, as REG_X - REG_X for the offset of a register from a base that happens to be the same, are written so on purpose.
From the rule's source, identical_operands.rs.
Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/cpp:identical-operands" = "off"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/cpp:identical-operands] reason="..."tx0 explain tx0/cpp:identical-operands shows the same in the terminal. Found a false positive? Report it.