In fact there is a reason.
Namely, the name of a function is in scope inside a function, but not in the trailing-return-type specification. Lambdas are exempt because they don't have names, although I think a variable being initialized from the lambda, typed by inference, is also in scope, so they already suffer this problem even with the standard syntax (workaround).
With the name of the function in scope, it's possible to construct an infinite circular type dependency. e.g.
auto fact(int n)
{
return (n > 0)? n*fact(n-1): 1;
}
In this case typing is consistent for several choices of return type... int
, long long
, float
, and double
, as well as std::complex<double>
, etc.
No problem with trailing-return-type, the code is simply illegal:
auto fact(int n) -> decltype((n > 0)? n*fact(n-1): 1) /* unknown identifier fact */
In another example, it's inconsistent for any choice of return type:
auto f(int a)
{
char r[sizeof(f(a))+1];
return r;
}
What does your new-and-improved g++ do with this?
auto fact = [&](int n){ return (n > 0)? n*fact(n-1): 1; };