There really is a reason.
Namely, the function name is inside the scope inside the function, but not in the specification of the trailing-return type. Lambdas are freed up because they have no names, although I think that the variable initialized from lambda, entered 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, you can build an infinite circular dependence. eg.
auto fact(int n) { return (n > 0)? n*fact(n-1): 1; }
In this case, typing is consistent for several variants of the return type ... int , long long , float and double , as well as std::complex<double> , etc.
There is no problem with trailing-return-type, the code is simply illegal:
auto fact(int n) -> decltype((n > 0)? n*fact(n-1): 1)
In another example, this contradicts 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; };
Ben voigt
source share