Statement after an unconditional terminator is unreachable
ID |
c.correctness.unreachable_code |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Dead Code |
Language |
C / C++ |
Description
This statement can never execute: it directly follows a return, break, continue, or throw, which unconditionally leaves the block. Dead code hides mistakes (a terminator placed too early) and misleads readers. Remove the unreachable statement, or move the terminator if it was misplaced.
Rationale
This statement can never execute: it directly follows a return, break, continue, or throw, which unconditionally leaves the block. Dead code hides mistakes (a terminator placed too early) and misleads readers. Remove the unreachable statement, or move the terminator if it was misplaced.
The following code illustrates the pattern detected by this rule:
int after_return(int x) {
// FLAGGED: Statement after an unconditional terminator is unreachable
return x;
printf("never runs\n");
}