Proposal: "void f() { return 7; }" should be illegal
Jason House
jason.james.house at gmail.com
Tue Sep 29 04:43:55 PDT 2009
bearophile Wrote:
> Don:
>
> > In the docs for "return statement" in statement.html it says:
> > ---
> > ReturnStatement:
> > return;
> > return Expression ;
> >
> > Expression is allowed even if the function specifies a void return type.
> > The Expression will be evaluated, but nothing will be returned.
>
> I agree that making the language a little more strict in such regards is better.
>
>
> > This makes sense for things we definitely want to allow, such as:
> > void foo() { return bar(); }
> > where bar() is another void function.
>
> If bar() is a void function then "return bar();" looks like a bug. Why do you want to allow such semantically wrong situation?
>
> Bye,
> bearophile
I believe the argument is to allow templated code to gracefully handle a void return type without special cases. It doesn't quite work since void is not a valid type for intermediate variables (leads to increased code duplication)
More information about the Digitalmars-d
mailing list