A case of a switch falls through into the next one without saying so

tx0/c:fallthroughrecommendedwarningbug

What it finds

A case of a switch whose statements run on into the next case, without break, return, goto or continue at their end: often a break was forgotten.

Falling through on purpose is marked with a comment that says so, such as /* fall through */ or // FALLTHRU, with the kernel's fallthrough;, with __attribute__((fallthrough)) or [[fallthrough]], or with a macro whose name says fallthrough, and those cases are left alone. So is a case whose last statement calls a function of the program, which may not return, or is a name alone, which may be a macro that jumps, one with a directive at its end, and one that falls into a case that only breaks.

From the rule's source, fallthrough.rs.

Example from the rule's tests
#include <stdlib.h> void fatal(const char *message); int classify(int c, int *count){  int r = 0;  switch (c) {  case 1:    r = 1;  case 2:tx0 reports: the case before falls through into this one    r += 2;    break;  case 3:    r = 3;    /* fall through */  case 4:    r += 4;    // FALLTHRU  case 5:    if (r)      return r;  case 6:tx0 reports: the case before falls through into this one    r = 6;    fallthrough;  case 7:    fatal("seven");  case 8:    exit(1);  case 9:  case 10:    r = 10;    return r;  case 11:    {      r = 11;    }  case 12:tx0 reports: the case before falls through into this one    r++;  default:    break;  }  switch (c) {    int unused;  case 1:    r = 1;#ifdef TWO    break;#endif  case 2:    if (r)      break;    else      return 0;  case 3:    count[0]++;  }  return r;}
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:fallthrough" = "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:fallthrough] reason="..."

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