This seems like a bad fit for unreadVariable/unusedVariable because there would be no loop without declaring the variable. Currently we don't flag empty loop/if/... scopes.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I found a false negative in Cppcheck 2.21.0 and 2.22 dev when a range-based for loop initializes its loop variable but the body never reads it.
Affected tool
Cppcheck 2.21.0; also reproduced with Cppcheck 2.22 devAffected checker
Cppcheck unreadVariableMinimal reproducer
Reproduction command
Current behavior
Cppcheck produces no
unreadVariableorunusedVariablediagnostic.Expected behavior
Cppcheck should report line 2 because each value assigned to the loop variable is never read.
This seems like a bad fit for unreadVariable/unusedVariable because there would be no loop without declaring the variable. Currently we don't flag empty loop/if/... scopes.