DMD warnings

Don Clugston dac at nospam.com.au
Mon Mar 13 23:51:59 PST 2006


Frank Benoit wrote:
> DMD makes warnings for sometimes serious errors.
> The user can compile with -w to get the warnings.
> For any bigger program it should be a good idea to switch this on.
> 
> But D is specially for "People who compile with maximum warning levels
> turned on and who instruct the compiler to treat warnings as errors."
> (see http://www.digitalmars.com/d/overview.html "who is D for").
> Including third party code can be anoying if this code is not warning
> free. e.g. phobos, mango, ares, ...
> 
> I say: lets remove the -w switch and treat all warnings as errors. No
> more nice to have warnings! Instead the user has to write the program
> allways error/warning free. If one specific warning can't be removed,
> the user has to tell the compiler with:

The problem is, those warnings are things that Walter thinks should not 
be errors. More precisely, they are code constructs that are OK, 90% of 
the time (at least, that's the case for narrowing conversions). We need
to more precisely capture the bad 10%, so that they can be turned into 
errors. Here's a few things that could be done:

* The warning about "length" can become an error, now that we have "$".
* No return value really should be an error, except when the function 
includes some inline asm. We need some way of stating that the end of 
the function is never reached, perhaps with something like "assert return":

void f(){
   for (; ;) {
     if (somevolatilefunc()) return;
     sleep();
   }
   assert return;
}

Leaving off the return statement is an error I make all the time, it 
really should not be a warning.

* Maybe something for the default in switch statements, too.
* Narrowing conversions are a big problem. I can't see how it could be 
solved, other than by introducing a narrowcast() operator (which could 
possibly throw an exception if the condition is violated).

> pragma( nowarn, 234 ){
> 	// code generating the warning 234
> }
> 
> So it is documented in the code. This is nice.
But it looks horrible, and it's only purpose is to turn off the warning.
Warnings are indications of problems in the language semantics -- it 
means the compiler doesn't have enough information to determine if the 
construct is erroneous or not. The solution is definitely not to make 
the construct always an error.
It would definitely be good to eliminate warnings. I know Walter hates them.



More information about the Digitalmars-d mailing list