内部循环中的匿名结构

Saq*_*ain 4 c++ gcc g++

下面的代码用g ++编译好

#include <iostream>
using namespace std; 

int main() 
{
    for (struct { int i; double j; } x = {0,0};  x.i < 10; ++x.i, x.j+=.1)
    {
        std::cout << x.i << " " << x.j << '\n';
    }
}
Run Code Online (Sandbox Code Playgroud)

但是使用MSVC2005我会收到错误

error C2332: 'struct' : missing tag name
error C2143: syntax error : missing ')' before '{'
warning C4094: untagged 'struct' declared no symbols
error C2059: syntax error : 'empty declaration'
error C2143: syntax error : missing ';' before ')'
error C2143: syntax error : missing ';' before ')'
error C2065: 'x' : undeclared identifier
error C2059: syntax error : '{'
error C2143: syntax error : missing ';' before '{'
error C2143: syntax error : missing ';' before '}'
error C2228: left of '.i' must have class/struct/union
1>        type is ''unknown-type''
error C2228: left of '.i' must have class/struct/union
1>        type is ''unknown-type''
error C2228: left of '.j' must have class/struct/union
1>        type is ''unknown-type''
error C2059: syntax error : ')'
error C2143: syntax error : missing ';' before '{'
error C2228: left of '.i' must have class/struct/union
1>        type is ''unknown-type''
error C2228: left of '.j' must have class/struct/union
1>        type is ''unknown-type''
Run Code Online (Sandbox Code Playgroud)

我想知道循环中的匿名结构是"扩展"还是语言功能,MSC2005是否缺少它?

Jes*_*ood 7

这是msvc中的一个错误.不幸的是,它的优先级列表并不高.

  • "因为无法修复而关闭":O (4认同)
  • @stardust_:我[再次报告](https://connect.microsoft.com/VisualStudio/feedback/details/782926/class-declaration-fails-in-for-loop). (3认同)