[英]Lambda capture, initializers and nested struct
Could someone explain what is happening here (GCC 7.3):有人可以解释这里发生的事情(GCC 7.3):
#include <thread>
#include <iostream>
struct A
{
struct B {};
};
int main()
{
int var = 0;
std::thread([c=A::B(), var](){ }); // error: ‘var’ was not declared in this scope
std::thread([c=A(), var](){ }); // OK
std::thread([c=A::B(), var=var](){ }); // OK
return 0;
}
When I capture nested struct I got:当我捕获嵌套结构时,我得到:
'var' was not declared in this scope
“var”未在此范围内声明
On the other hand, capturing non-nested struct works.另一方面,捕获非嵌套结构有效。 Also capturing with initialization works.
还捕获初始化工作。 Also all cases work in Visual Studio.
此外,所有案例都适用于 Visual Studio。
Must be a bug in GCC 7.x since 8.1 accepts it.必须是 GCC 7.x 中的一个错误,因为 8.1 接受它。 https://godbolt.org/z/xXw6qN
https://godbolt.org/z/xXw6qN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.