That should be [dcl.spec.auto]/11 (quoting n3797)
If the type of an entity with an undeduced placeholder type is needed to determine the type of an expression, the program is ill-formed. Once a
return
statement has been seen in a function, however, the return type deduced from that statement can be used in the rest of the function, including in otherreturn
statements.
So, by reverting the return-statements, the return type deduction can succeed:
#include <iostream>
int main() {
auto append = [](auto &&cnt, auto &&me,
auto &&a, auto &&p1, auto &&...p) -> decltype(auto)
{
if(sizeof...(p) <= cnt)
return a;
return me(++cnt, me, a << p1, p..., 0);
};
append(0u, append, std::cout, 1, 2, 3, 4);
}