CQM-DeadImplementation

Unreachable statements

Required inputs: IR

Statements that cannot be reached in the control flow should be removed.
Motivation

All code should be minimal, i.e. every single instruction serves directly or indirectly to ensure the quality of the application (functional as well as non-functional). If there are instructions that are not executed under any circumstances, they are superfluous and thus complicate all maintenance work on the code.

Dead code that can be reliably identified with tools is present on a control flow path

  • after a return statement or
  • after an exception has been thrown.

This rule is based on the CQM Quality Indicator: tote Implementierung (p. 294-296).

Reference

Simon, Frank/ Seng, Olaf/ Mohaupt, Thomas (2006): Code-Quality-Management: Technische Qualität industrieller Softwaresysteme transparent und vergleichbar gemacht, 1st ed., Heidelberg, Germany: dpunkt.verlag GmbH.

Possible Messages

Key

Text

Severity

Disabled

function_never_called

{what} never called

None

False

function_only_called_from_uncalled_function

{what} only called from uncalled function

None

False

function_only_called_from_uncalled_function_or_dead_branches

{what} only called from uncalled function or from dead branches

None

False

unreachable_code

Unreachable code

None

False

Options

disregard_logical_shortcut

disregard_logical_shortcut : bool = False

Whether constant literal conditions must not be caused by logical shortcut evaluations like false && ... or true || ....
 

report_dead_if_branch_with_const_literal_condition

report_dead_if_branch_with_const_literal_condition : bool = True

Whether bodies of if-branches with constant literal conditions should be reported.
 

use_semantic_analysis

use_semantic_analysis : bool = True

If false, ignore results from static semantic analysis and only consider syntactical information to compute reachability.