[LLVMdev] MS C++ gives error C2371 on this code while (obviously)gcc compiles it fine

Sherief N. Farouk sherief at mganin.com
Thu Oct 2 11:30:24 PDT 2008


> This can be changed in the project settings for a VC++ project.  
> I think it was called something like "Enforce for loop conformance" or
so...
> This is something I always change though.

Nope. The for loop conformance option fixes a VC++6 "feature" where
identifiers declared in the for loop initialization are visible after the
for loop's body.
VC6:
for(int i = 0; i < 5; ++i)
{
    ...
}
std::cout << i; //Prints "5"

This is illegal in ISO C++, and by default in VC8 and beyond (maybe earlier,
but I moved from 6 to 8). The VC++ option enable VC6-like behavior for
legacy code. What Jay pointed out is Yet Another For Scope FUBAR.

To the VC team's credit, though, "inline any suitable" is pure awesome.

- Sherief





More information about the llvm-dev mailing list