A condition assigns a constant where a comparison was meant
What it finds
if (x = 1): the condition assigns a constant, so it is always true, or always false for zero, and the variable is overwritten. A comparison, x == 1, was meant.
The assignment must be the whole condition of an if, while, do or for, without extra parentheses, which mark an assignment as meant, and the value an integer or character literal. A fix to == is offered, but not applied without asking, since it changes what the program does.
From the rule's source, constant_assignment_condition.rs.
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/cpp:constant-assignment-condition" = "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/cpp:constant-assignment-condition] reason="..."tx0 explain tx0/cpp:constant-assignment-condition shows the same in the terminal. Found a false positive? Report it.