RED-unused-var-all
In this section:
Synopsis
A variable is neither read nor written for any execution path.
Enabled by default
Yes
Severity/Certainty
Low/High

Full description
A variable is neither read nor written for any execution path. Writing includes initialization, and reading includes passing the variable as a parameter in a function call. This is not unsafe as such, but might indicate a logical error. This check is identical to MISRAC++2008-0-1-3.
Coding standards
- CERT MSC13-C
Detect and remove unused values
- CWE 563
Unused Variable
- MISRA C++ 2008 0-1-3
(Required) A project shall not contain unused variables.
Code examples
The following code example fails the check and will give a warning:
int example(void) {
int x; //this value is not used
return 0;
}
The following code example passes the check and will not give a warning about this issue:
int example(void) {
int x = 0; //OK - x is returned
return x;
}