gcc-2.7.0 implements the new ANSI/ISO rule on the scope of variables declared in for loops.
for (int i = 1; i <= 10; i++) { // do something here } foo(i);
In the above example, most existing C++ compilers would pass the
value 11 to the function foo
. In gcc 2.7 and in the ANSI/ISO
working paper, the scope of i
is only the for loop body, so
this is an error. So that old code can be compiled, the new gcc has
a flag -fno-for-scope
that causes the old rule to be used.
As of 2.7.1, the compiler attempts to issue warnings about code that has different meanings under the two sets of rules, but the code is not perfect: the intent was that code that has valid, but different, meanings under the ARM rules and the working paper rules would give warnings but have the new behavior, and this doesn't seem to happen.
The -ffor-scope
flag under 2.7.1 and 2.7.2 gives the 2.7.0 behavior.