MISRA C++:2023 Rule 0.2.1
Description
Rule Definition
Variables with limited visibility should be used at least once
Rationale
Unused variables take up unnecessary space without contributing to the program output. The presence of unused variables might also indicate a programming error, such as an incorrect variable being used elsewhere.
Polyspace Implementation
The rule checker reports violations on unused variables with internal linkage, for instance:
Unused local variables
Unused global variables declared
static
Unused global variables declared outside a header file with a
const
orconstexpr
qualifier but not anextern
qualifierUnused global variables in an anonymous namespace
The rule violation is reported on the variable declaration.
The checker does not report violations on unused variables of class type with a user-defined constructor or destructor.
Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Language independent issues |
Category: Advisory |
Version History
Introduced in R2024b