문제

In Visual Studio 2013, I wrote the following in an empty, brand-new command-line solution:

int main(int argc, char* argv[])
{
    int xs[1];
    for (auto x : xs)
        do
            ;
        while (0);
    return 0;
}

When I compile, I get the following error:

error C2059: syntax error : '}'

on the line containing the single semicolon. Have I found a compiler bug? Or is the range-based for loop subtle beyond my comprehension?

도움이 되었습니까?

해결책

To summarise the comments for anyone coming this way in the future:

This is clearly a compiler bug in Visual Studio 2012 and 2013. The error message given by Visual Studio is clearly bogus, and other compilers work as expected.

The simplest workaround for me is to just put braces around the whole do-while loop like so:

int main(int argc, char* argv[])
{
    int xs[1];
    for (auto x : xs)
    {
        do
            ;
        while (0);
    }
return 0;
}

Thanks to everyone for your help.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top