Apparently there is evidence that unused variables in C-like
languages correlate with bugs:
https://kev.inburke.com/slides/errors/#error-correlations
One problem with ruling out some classes of unused variables
(like unused function arguments, unused private module-level
variables, unused function-local variables, and so on) is that
when you are writing code you sometimes add some unused
variables, that you usually will use or remove later.
So you usually don't want an error or warning for unused
variables when you are writing code, but later there is a moment
when you probably want to clean up your code and remove any
unused variable to make the code more clean and tight.
A simple solution in C-languages is to add a compiler switch that
allows to disallow or allow the unused variables according to the
phase of your working on the code. But compiler switch
proliferation can be a problem (unless you use an IDE, that
offers you a button to enable/disable such tests).
Another solution is to leave such tests out of the core compiler,
and put them in a lint tool that you run when you think your code
is in good shape.
Bye,
bearophile