Wish: Variable Not Used Warning

Don nospam at nospam.com.au
Mon Jul 7 01:24:14 PDT 2008


Don wrote:
> Walter Bright wrote:
>> Nick Sabalausky wrote:
>>> I don't suppose there's any chance of DMD getting a warning for 
>>> variables/arguments that are declared but never accessed? Just today 
>>> alone there's been two bugs I spent 10-30 minutes going nuts trying 
>>> to track down that turned out to be variables I had intended to use 
>>> but forgot to. 
>>
>> The problem with unused variable warnings is they are annoying when 
>> you're developing code in an iterative manner. They get in the way 
>> when you're commenting out sections of code to try and isolate a 
>> problem. They can be a problem when using "version" and "static if" 
>> statements.
>>
>> So, why not just turn off the warnings?
>>
>> The problem with warnings is that if there are n warnings, there are 
>> essentially n factorial different versions of the language. If you're 
>> faced with compiling someone else's code (like you downloaded it off 
>> the internet and have to compile it because it only is distributed as 
>> source) and warnings go off, is that a bug in the code or not? What do 
>> you do?
>>
>> Some shops have a "thou shall compile with warnings enabled, and there 
>> shall be no warning messages." That causes problems when you port the 
>> code to a different compiler with a different, even contradictory, 
>> notion of what is a warning. So then you wind up putting wacky things 
>> in the code just to get the compiler to shut up about the warnings.
>>
>> Those kind of things tend to interfere with the beauty of the code, 
>> and since they are not necessary to the program's logic, they tend to 
>> confuse and misdirect the maintenance programmer (why is this variable 
>> pointlessly referenced here? Why is this unreachable return statement 
>> here? Is this a bug?)
> 
> I agree. Unfortunately, there's a problem with the 'optional' warnings 
> we have in DMD right now. They are not optional for libraries. If a 
> library generates warnings, then it is not usable by anyone who wants to 
> compile with warnings enabled.
> 
> I'd love to see the warnings tightened up so that they can become bugs.

Of course, I mean 'errors' not bugs!

> 
>> There is a place for warnings, however. That is in a separate static 
>> analysis tool (i.e. lint, coverity, etc.) which can be armed with all 
>> kinds of heuristics with which to flag questionable constructs. I 
>> don't think they should be part of the compiler, however.



More information about the Digitalmars-d mailing list