Unused static variable¶
ID: cpp/unused-static-variableKind: problemSecurity severity: Severity: recommendationPrecision: highTags: - efficiency - useless-code - external/cwe/cwe-563Query suites: - cpp-security-and-quality.qls
Click to see the query in the CodeQL repository
This rule finds static variables that are never accessed. These static variables should be removed, to increase code comprehensibility, reduce memory usage and avoid misuse. Unused staticconst variables could also be an indication of a defect caused by an unhandled case.
Recommendation¶
Check that the unused static variable does not indicate a defect, for example, an unhandled case. If the static variable is genuinely not needed, then removing it will make code more readable. If the static variable is needed then you should update the code to fix the defect.
Example¶
voidf(){staticinti=0;//i is unused...return;}
References¶
Common Weakness Enumeration:CWE-563.