[Bug 180] New: DMD accepts a function with a non-void return type but no return statements
Don Clugston
dac at nospam.com.au
Wed Jun 7 08:26:31 PDT 2006
Derek Parnell wrote:
> On Wed, 07 Jun 2006 22:19:47 +1000, <d-bugmail at puremagic.com> wrote:
>
>
>> As such, the compiler should be reporting an error on such code as the
>> above.
>
> This is one of the 'optional' errors. You can get the compiler to issue
> an error by using the -w switch.
I really don't understand why it's optional.
It indicates either: a very common bug (left off a return statement).
or.. a coding documentation bug (having no return is so rare, that it
needs a comment in the source code. Why not make the comment an assert(0)?).
To quote warnings.html:
warnings are either a symptom of broken language design or a useful
'lint' like tool to analyze code and look for potential trouble spots.
Most of the time, those trouble spots will be legitimate code intended
to be that way. More rarely, it may indicate an unintentional error on
the part of the programmer.
Leaving off a return statement is not normally legitimate code. It's
really easy to do by mistake.
(In contrast, "implicit conversion of expression expr of type type to
type can cause loss of data" is almost certainly legitimate code rather
than an error).
However, I think the error message should not just be "missing return
statement", it should be more like:
"missing return statement, or assert(0) if code is unreachable".
Certainly it should be an error if a function doesn't contain any return
statements at all!
More information about the Digitalmars-d-bugs
mailing list