int main() { auto f = [] { auto f = [] { auto f = [] { auto f = [] { auto f = [] { }; }; }; }; }; }
int main() { auto f = [] { auto f = [] { auto f = [] { auto f = [] { auto f = [] { auto f = [] { }; }; }; }; }; }; }
而且,它们的编译速度很慢.这有什么解释吗?我正在使用Visual C 2013.
更新
这似乎是Visual C中的一个错误,我已向Microsoft报告过:https://connect.microsoft.com/VisualStudio/feedback/details/813755/nested-lambdas-in-visual-c-2013-are-very-slow-to-compile-and-generate-huge-object-file.
解决方法
The C++ standard recommends limits for varIoUs language constructs. The following is a list of constructs where the Visual C++ compiler does not implement the recommended limits. The first number is the recommended limit and the second number is the limit implemented by Visual C++:
并包括以下项目:
Nesting levels of compound statements,iteration control structures,and selection control structures [256] (256).
如果我们看一下C++ draft standard中的语法,复合语句最终会回到包含lambda-expression的primary-expression.所以Visual Studio应该支持多达256级的嵌套.
您还可以通过查看lambda-expression的语法来看到这一点,如下所示:
lambda-introducer lambda-declaratoropt compound-statement
draft standard在附录B中有一套建议限值,但它们只是指导原则,不能确定是否符合要求.
更新
最近更新了OP提交的bug report以表明将在未来的版本中修复.