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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With