A statement follows a return, break, continue or goto in the same block and never runs

tx0/c:unreachable-coderecommendedwarningsmell

What it finds

return err; cleanup(p);: nothing can reach a statement right after a jump unless it carries a label, so it is dead; often it was meant to come before the jump.

The statement must follow a return, break, continue, goto, or a call of the C library's exit or abort, in the same block, with no directive between, and hold no label anywhere inside, which a switch could jump to. Declarations, empty statements and a break after a return, which some write out of habit, are left alone.

From the rule's source, unreachable_code.rs.

Example from the rule's tests
#include <stdlib.h> void cleanup(int *p); int run(int *p, int n){  switch (n) {  case 1:    return 1;    cleanup(p);tx0 reports: this statement is never reached  case 2:    break;  }  if (n > 3) {    exit(1);    n++;tx0 reports: this statement is never reached  }  if (n > 2)    goto out;  return 0;  n = 5;tx0 reports: this statement is never reachedout:  cleanup(p);  return n;}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/c:unreachable-code" = "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:unreachable-code] reason="..."

tx0 explain tx0/c:unreachable-code shows the same in the terminal. Found a false positive? Report it.