A condition of an if-else chain repeats an earlier one

tx0/cpp:duplicate-conditiondefaultwarningreliability/control-flowdepth fastbug

What it finds

if (a) ... else if (a) ...: a condition that repeats an earlier one of the same chain is false whenever it is reached, so its branch never runs. Usually one of the two was meant to test something else.

Between two conditions of a chain only conditions run, so the chain is followed as long as no condition can change what a later one reads: it ends at a condition that calls something, which may be a macro with effects, assigns, increments or decrements. Names defined as macros in the file and names of volatile objects end it too, and so does a conditional directive between two conditions, since the two may never be compiled together.

From the rule's source, duplicate_condition.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:

tx0.toml
[rules]
"tx0/cpp:duplicate-condition" = "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:duplicate-condition] reason="..."

tx0 explain tx0/cpp:duplicate-condition shows the same in the terminal. Found a false positive? Report it.