UnreachableCode -- Check for Unreachable Code
Go Up to C++ Audits
Description
Checks for unreachable code.
For example, UnreachableCode checks whether a loop body is never executed. That is, UnreachableCode detects situations where the repeat condition of a while or for loop always evaluates to false
. The body of such a loop will never execute.
Also, UnreachableCode checks whether a statement is unreachable. That is, UnreachableCode detects situations where a statement can never be executed.
Incorrect
int count(int limit) {
if (limit >= 0) {
...
} else {
for (int i = 0; i < limit; i++) {
...
}
}
}
Or
int* arr = new int[size];
if (arr == 0) {
return;
}