int main()
{
auto l = [x = 10]() -> decltype(x) {};
}
clang++ 4.0 rejects this code with the following error:
error: use of undeclared identifier 'x' auto l = [x = 10]() -> decltype(x) {}; ^g++ 7 rejects this code with the following error:
In function 'int main()': error: 'x' was not declared in this scope auto l = [x = 10]() -> decltype(x) {}; ^ error: 'x' was not declared in this scope In lambda function: warning: no return statement in function returning non-void [-Wreturn-type] auto l = [x = 10]() -> decltype(x) {}; ^
Is this a bug or is there something in the standard that explicitly prevents objects captured with the C++14 generalized syntax from being used in the lambda's trailing return type?
Note that both compilers are happy with non-generalized captures:
int main()
{
int x = 10;
auto l = [x]() -> decltype(x) { return 0; };
}
intused to be a default return type, will gcc deduce any other type?int... updating the questiondecltypeand lambdas, e.g. this.