------- Comment #4 from redi at gcc dot gnu dot org 2010-04-30 11:22 -------
(In reply to comment #3)
> > a function with a missing return is valid
>
> I just can't reconcile that with the following line from the C++ standard: "It
> is now invalid to return (explicitly or implicitly) from a function which is
> declared to return a value without actually returning a value." Any insights?
Apologies, you're right, in C++ it's not valid and is always undefined
behaviour.
But there have been long discussions on the standard committee reflector about
why it cannot be a "diagnostic required" error, rather than undefined
behaviour. There are cases which are either not diagnosable or cannot be
written, such as this example from Doug Gregor:
in generic code, there might not be a way to create a value with the
appropriate type. For example:
template<typename T>
T maybe_call(std::function<T(void)> f) {
if (f)
return f();
else
abort_program();
// Cannot write a return here, because we have no way to create
a value of type 'T'
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43943