The following code compiles successfully with g++ 7.3.0 and fails to compile with clang++ 6.0.0 (compilation flags are -std=c++17 -Wall -Wextra -Werror -pedantic-errors
):
auto foo = [](auto, auto... tail) {
if constexpr (sizeof...(tail) > 0)
{
return foo(tail...);
}
else
{
return 42;
}
};
int main()
{
}
clang++ compilation error message:
error: variable 'foo' declared with deduced type 'auto' cannot appear in its own initializer
return foo(tail...);
What behavior is standard compliant in this case?