Proposal: "void f() { return 7; }" should be illegal

bearophile bearophileHUGS at lycos.com
Tue Sep 29 04:23:54 PDT 2009


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



More information about the Digitalmars-d mailing list