Howard said:
Howard wrote:
[...]
You removed the return statement, but the function still specified a
return type? That shouldn't even compile! I'd get a new compiler if it
does.
Why shouldn't it compile? Which part of the Standard says that a program
that has such function is ill-formed? While you're looking for it, check
out 6.6.3/2, the last sentence.
V
I don't have a copy of the Standard, but Stroustrup's book "The C++
Programming Language", in section 7.3, states: "A value must be returned
from a function that is not declared void". Obviously, stating that
something is required doesn't neccessarily mean that the standard
dictates that a program that does not meet such a requirement is
ill-formed, but surely in this case it is...?
It isn't. I do have a copy of the Standard and I gave you the location
in it where you should look (when you get yourself a copy, that is).
My compiler(s) certainly won't let it
compile, and I can't see any reason why any compiler _would_ allow it.
What if your function is never called? The fact that it doesn't return
has no relevance if it's never called, is it? What if even when it's
called, it never returns, only throws? Or simply never returns because
it has an infinite loop in it? Again, any return statement would be
irrelevant. I shouldn't have to put anything in my code that never gets
executed ("dead code").
In any case, your view is apparently different from the view of the
Committee and of many compiler implementors out there. Which compilers
refuse to compile a non-void function without a return statement, BTW?