MISRA C++:2023 Rule 0.2.1
Description
Rule Definition
Variables with limited visibility should be used at least once 1
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.
Local variables of a function that contains assembly code in an
asm
block.
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 R2024b1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.