DMD warnings

Frank Benoit frank at nix.de
Sat Mar 11 08:19:52 PST 2006


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:

pragma( nowarn, 234 ){
	// code generating the warning 234
}

So it is documented in the code. This is nice.

Perhaps it makes sense to define a standard set of warnings in the
d-specification and have literals for them:

pragma( nowarn, NoReturnAtEndOfFunction ){
	int f(){
		generateError( "throw the funky exception" );
	}
}

The compiler implementation can add his own warnings, additional to the
d-spec. The user can switch them off globally by cmdline switch. So
existing code can allways compile.

In MISRA, a coding standard for implementing C/C++ in automotive
industry, the user has a big set of rules. He should write the code,
according to the rules. If it is not possible to implement something
without breaking a rule, this is OK, but the programmer has to document
it with the cause, why he is breaking the rule. In D, this can be aided
by the compiler with such a this mechanism.

pragma( nowarn, identifier, "cause" ){
}


Frank Benoit => keinfarbton




More information about the Digitalmars-d mailing list