Cppcheck produces no unreadVariable diagnostic for divisor.
Expected behavior
The right-hand side of true || divisor is not evaluated, so the value stored in divisor is never read. Cppcheck should report the unused initialization.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We don't warn about the expression return true || divisor;, which is arguably dubious, but may be intentional, similar to if (false) etc. So we won't report the induced unreadVariable either.
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 when a local variable is used only on the unevaluated right-hand side of a short-circuit expression.
Affected tool
Cppcheck 2.21.0Affected checker
unreadVariableMinimal reproducer
Reproduction command
Current behavior
Cppcheck produces no
unreadVariablediagnostic fordivisor.Expected behavior
The right-hand side of
true || divisoris not evaluated, so the value stored indivisoris never read. Cppcheck should report the unused initialization.We don't warn about the expression
return true || divisor;, which is arguably dubious, but may be intentional, similar toif (false)etc. So we won't report the inducedunreadVariableeither.