Jason House wrote:
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.
Well maybe the change could be made only to functions that are not
templated.