Unused Arguments Aren't a Problem When Recursing Right?
nullterminatedstrings.com
nullterminatedstrings.com
Are unused arguments a problem when recursing? I can imagine they are if they're taking up stack space and you're doing an awful lot of recursing (I don't really use recursion enough in my C++ code to really run into issues like this, so I am a little ignorant on the side effects of recursing deeply).
Anyway it's time for bed and I'm sure this article is going to be giving me nightmares tonight.
This is a general point: More warnings can help find more bugs earlier - but you do have to worry about false positives, and warnings that increase compile time can also be a net negative.
The author's example is probably simple and efficient enough to add to a compiler, assuming that it performs some basic recursion analysis already.
To detect it, split the recursive function into two, one that recurses and one that does the job at the end. Both can take the same relevant arguments and the latter function will detect any unused parameters.
But that feels like the wrong way to analyze this. Even though a full solution isn't practical, a limited one may be.
I think the right approach here is to run slow code analysis tools frequently, but less frequently than compiles.