int main()
{
auto l = [x = 10]() -> decltype(x) {};
}
clang++ 4.0 rejects this code,错误如下:访问概括捕获在拉姆达对象后返回类型
error: use of undeclared identifier 'x' auto l = [x = 10]() -> decltype(x) {}; ^
g++ 7 rejects this code,错误如下:
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) {}; ^
这是一个错误还是标准中有某些东西可以显式地阻止在lambda的尾随返回类型中使用用C++ 14通用语法捕获的对象?
注意,两种编译器很高兴与非广义捕获:
int main()
{
int x = 10;
auto l = [x]() -> decltype(x) { return 0; };
}
'int'曾经是一个默认的返回类型,gcc会推导出其他类型吗? – alexeykuzmin0
@ alexeykuzmin0:很好。 [它始终“推断”'int'](http://melpon.org/wandbox/permlink/OivD8IYUT3Jq0720)...更新问题 –
有一些奇怪的例子,例如decltype和lambda, [本](https://groups.google.com/a/isocpp.org/forum/#!topic/std-discussion/6-VL5bzK6Ik)。 – TartanLlama