DMD warnings

Frank Benoit frank at nix.de
Tue Mar 14 01:12:25 PST 2006


Don Clugston schrieb:
> 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. ...
> * Maybe something for the default in switch statements, too.
> * Narrowing conversions are a big problem. 

The only way to capture the bad 10% is to fix all. Thats my point,
nobody should ignore warnings, because this bad 10%.

So lets force them to be errors with a back door for emergency.

>> 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.

Yes it looks horrible and it shows a horrible situation. It was not
possible to fix a warning.
This should be used rarely. Instead fix warnings:
Missing cast => add one
Missing return => add a return, assert(false) or throw
...

int i =3;
uint s = cast(uint)i;

I really think it is better style to have this explicite cast in the
code. Because a reader can see, it is not only an assignment, there is
also a cast which can have side effects.

If you ignore warnings you will not be aware of this, if you read this
code in half a year.

But perhaps there is a situation you cannot fix the warning or don't
want to change the code in this way. So you have this back door.

> 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.

Sure! It is easy to provide the information to the compiler. Add the
cast, return, ...
This process is valueable because you notice an error, decide to fix the
warning or decide to switch this warning off for the certain sequence.

So treating warnings as errors, forces the user to think about. And that
is the sense of warnings.

Frank



More information about the Digitalmars-d mailing list