Could someone explain what is happening here (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
On the other hand, capturing non-nested struct works. Also capturing with initialization works. Also all cases work in Visual Studio.
Must be a bug in GCC 7.x since 8.1 accepts it. https://godbolt.org/z/xXw6qN
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.