Unreachable code
Code cannot be reached during execution
Description
This check determines whether a section of code is statically unreachable. To determine reachability, the check evaluates conditions that decide if a section of code is executed.
If at least one of the conditions statically evaluates to true, the section of code is considered reachable.
If all the conditions always evaluate to false, the section of code appears as unreachable code.
The conditions that are not evaluated at all or that always evaluate to true also appear as unreachable code.
Examples of unreachable code include the following:
If an
if
condition expression always evaluates to false, the corresponding code branch cannot be reached. On the Source pane, the opening brace of the branch is gray.If an
if
condition expression always evaluates to true, the condition is redundant. On the Source pane, theif
keyword appears gray.The code follows a
break
orreturn
statement.
If an opening brace of a code block appears gray on the Source pane, to highlight the entire block, double-click the brace.
The check operates on code inside a function. The checks Function not called and Function not reachable determine if the function itself is not called or called from unreachable code.
Diagnosing This Check
Examples
Check Information
Group: Data flow |
Language: C | C++ |
Acronym: UNR |