A condition is an assignment without parentheses that mark it as meant
What it finds
if (a = b): an assignment as the whole condition of an if, while, do or for is often a comparison with one = missing. Where the assignment is meant, extra parentheses say so, as in while ((c = next()) != 0) or if ((p = find(x))), and the rule leaves those alone.
Assignments of constants are found by constant-assignment-condition instead.
From the rule's source, assignment_in_condition.rs.
int next(void); int f(int x, int y, int *p){ int r = 0; if (x = y)tx0 reports: the condition assigns y to x r++; while (x = next())tx0 reports: the condition assigns next() to x r++; if ((x = y)) r++; while ((x = next()) != 0) r++; if (x = 1) r++; if (x == y) r++; return r + *p;} 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:assignment-in-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/c:assignment-in-condition] reason="..."tx0 explain tx0/c:assignment-in-condition shows the same in the terminal. Found a false positive? Report it.