CWE-561

Dead Code. [Bad-Coding-Practices, Improper-Adherence-To-Coding-Standards]

Required inputs: IR, StaticSemanticAnalysis

The product contains dead code, which can never be executed. Dead code is code that can never be executed in a running program. The surrounding code makes it impossible for a section of code to ever be executed.
Demonstrative Examples
Example 1

The condition for the second if statement is impossible to satisfy. It requires that the variables be non-null. However, on the only path where s can be assigned a non-null value, there is a return statement.

Example Language:C++
    String s = null;
    if (b) {
        s = "Yes";
        return;
    }

    if (s != null) {
        Dead();
    }
Example 2

In the following class, two private methods call each other, but since neither one is ever invoked from anywhere else, they are both dead code.

Example Language:Java (Unsupported language for documentation only)
    public class DoubleDead {
        private void doTweedledee() {
            doTweedledumb();
        }
        private void doTweedledumb() {
            doTweedledee();
        }
        public static void main(String[] args) {
            System.out.println("running DoubleDead");
        }
    }

(In this case it is a good thing that the methods are dead: invoking either one would cause an infinite loop.)

Example 3

The field named glue is not used in the following class. The author of the class has accidentally put quotes around the field name, transforming it into a string constant.

Example Language:Java (Unsupported language for documentation only)
    public class Dead {
        String glue;

        public String getGlue() {
            return "glue";
        }
    }
Excerpts from CWE [https://cwe.mitre.org], Copyright (C) 2006-2026, the MITRE Corporation. See section 9.4. "3rd-Party Licenses" in the documentation for full details.

Possible Messages

Key

Text

Severity

Disabled

dead_call_false_branch

Function call condition is always true{dead_branch_type}

None

False

dead_call_false_branch_type_limits

Function call condition is always true due to limited range of data type{dead_branch_type}

None

False

dead_call_true_branch

Function call condition is always false

None

False

dead_call_true_branch_type_limits

Function call condition is always false due to limited range of data type{dead_branch_type}

None

False

dead_catch

Dead exception handler

None

False

dead_false_branch

Condition is always true{dead_branch_type}

None

False

dead_false_branch_type_limits

Condition is always true due to limited range of data type{dead_branch_type}

None

False

dead_false_branch_type_limits_in_context

Condition is true in context due to limited range of data type{dead_branch_type}

None

False

dead_global_var_false_branch

Global variable condition is always true{dead_branch_type}

None

False

dead_global_var_false_branch_type_limits

Global variable condition is always true due to limited range of data type{dead_branch_type}

None

False

dead_global_var_true_branch

Global variable condition is always false{dead_branch_type}

None

False

dead_global_var_true_branch_type_limits

Global variable condition is always false due to limited range of data type{dead_branch_type}

None

False

dead_param_dependent_var_false_branch

Parameter-dependent variable condition is always true{dead_branch_type}

None

False

dead_param_dependent_var_true_branch

Parameter-dependent variable condition is always false{dead_branch_type}

None

False

dead_param_false_branch

Parameter condition is always true{dead_branch_type}

None

False

dead_param_false_branch_type_limits

Parameter condition is always true due to limited range of data type{dead_branch_type}

None

False

dead_param_null_false_branch

Parameter is always equal to NULL{dead_branch_type}

None

False

dead_param_null_true_branch

Parameter is never equal to NULL{dead_branch_type}

None

False

dead_param_true_branch

Parameter condition is always false{dead_branch_type}

None

False

dead_param_true_branch_type_limits

Parameter condition is always false due to limited range of data type{dead_branch_type}

None

False

dead_true_branch

Condition is always false{dead_branch_type}

None

False

dead_true_branch_type_limits

Condition is always false due to limited range of data type{dead_branch_type}

None

False

dead_true_branch_type_limits_in_context

Condition is false in context due to limited range of data type{dead_branch_type}

None

False

dead_var_false_branch

Variable condition is always true{dead_branch_type}

None

False

dead_var_false_branch_type_limits

Variable condition is always true due to limited range of data type{dead_branch_type}

None

False

dead_var_true_branch

Variable condition is always false{dead_branch_type}

None

False

dead_var_true_branch_type_limits

Variable condition is always false due to limited range of data type{dead_branch_type}

None

False

declared_function_not_called

Declared function is not called

None

False

defined_function_not_called

Defined function is not called

None

False

do_while_only_once

Loop is only executed once, loop condition is always false

None

False

do_while_only_once_type_limits

Loop is only executed once, loop condition is always false due to limited range of data type

None

False

loop_cond_false

Loop body is dead, condition is always false

None

False

loop_cond_false_type_limits

Loop body is dead, condition is always false due to limited range of data type

None

False

loop_cond_true

Loop condition is always true

None

False

loop_cond_true_type_limits

Loop condition is always true due to limited range of data type

None

False

subexpression_false

Subexpression always evaluates to false

None

False

subexpression_false_type_limits

Subexpression always evaluates to false due to limited range of data type

None

False

subexpression_true

Subexpression always evaluates to true

None

False

subexpression_true_type_limits

Subexpression always evaluates to true due to limited range of data type

None

False

unreachable_short_circuit

Subexpression never evaluated due to short-circuiting operator

None

False

Options

ignore_copy_assignment_operators

ignore_copy_assignment_operators : bool = False

Whether uncalled copy assignment operators are allowed.

Other rules like the "rule of three" might require copy assignment operators as part of good class design, even if there are currently no callers of the copy assignment operator.

 

ignore_copy_constructors

ignore_copy_constructors : bool = False

Whether uncalled copy constructors are allowed.

Other rules like the "rule of three" might require copy constructors as part of good class design, even if there are currently no callers of the copy constructor.

 

ignore_move_assignment_operators

ignore_move_assignment_operators : bool = False

Whether uncalled move assignment operators are allowed.

Other rules like the "rule of three" might require move assignment operators as part of good class design, even if there are currently no callers of the move assignment operator.

 

ignore_move_constructors

ignore_move_constructors : bool = False

Whether uncalled move constructors are allowed.

Other rules like the "rule of three" might require move constructors as part of good class design, even if there are currently no callers of the move constructor.

 

only_check_defined_functions

only_check_defined_functions : bool = True

Whether only defined functions should be checked for being uncalled.
 

only_check_internal_or_private_methods

only_check_internal_or_private_methods : bool = False

Whether only function with internal linkage or private functions should be checked for being uncalled. This is a shortcut for a visibility.
 

only_check_static_or_private_methods

only_check_static_or_private_methods : bool = False

Whether only static functions or private functions should be checked for being uncalled. This is a shortcut for a visibility.
 

only_check_unit_locals

only_check_unit_locals : bool = False

Whether only global static functions should be checked for being uncalled.

Note: this option is automatically activated during single-file analysis.

 

report_do_while_false

report_do_while_false : bool = True

Whether do ... while(0) should be reported.
 

report_for_true

report_for_true : bool = True

Whether for(;;) ... should be reported.
 

report_while_true

report_while_true : bool = True

Whether while(1) ... should be reported.
 

suppress_attribute_maybe_unused

suppress_attribute_maybe_unused : FilterAction = 'suppress'

Filter action to apply to violations for objects marked as [[maybe_unused]] or __attribute__((unused)). If set to "suppress", findings will be reported but marked as suppressed. If set to "exclude", findings will not be reported at all. If set to "normal", no special treatment is applied and the finding is reported as usual.
 

visibility

visibility

Type: list[list[Visibility] | Visibility]

Default: []

Describes which functions should be checked for being uncalled as a disjunction of conditions where list elements may be conjunctions given as sublists. If the list is empty no restrictions apply apart those given by the shortcut options only_check_static_or_private_methods or only_check_internal_or_private_methods.
 

Option Types

These types are used by options listed above:

FilterAction

Used for the return value of add_filter() callbacks.
 

normal

The violation proceeds as usual.

exclude

The violation is excluded: The violation is discarded as if `--exclude` applied to it. The following filters won't get to see the violation, and it will not be imported into the database under any circumstances.

suppress

The violation is suppressed as if `AXIVION DISABLE` applied to it. Whether the violation gets imported into the database is controlled by the Axivion CI configuration.

Visibility

An enumeration.
 
  • PRIVATE

  • STATIC

  • NON_VIRTUAL

  • IN_ANONYMOUS_NAMESPACE