https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10852
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |msebor at gcc dot gnu.org Resolution|--- |FIXED --- Comment #7 from Martin Sebor <msebor at gcc dot gnu.org> --- I think this works correctly now. In C++ 98 mode GCC complains with -fpermissive. In C++ 11 and later it accepts the code as expected. Resolving as fixed. $ (set -x; cat t.C && for y in 98 11 17; do gcc -S -Wall -Wextra -Wpedantic -std=c++$y t.C; done) + cat t.C namespace X { int i; } void f() { for (int i=0; i<10; ++i) ; using namespace X; i; } + for y in 98 11 17 + gcc -S -Wall -Wextra -Wpedantic -std=c++98 t.C t.C: In function ‘void f()’: t.C:9:3: error: name lookup of ‘i’ changed for ISO ‘for’ scoping [-fpermissive] i; ^ t.C:9:3: note: (if you use ‘-fpermissive’ G++ will accept your code) t.C:9:4: warning: statement has no effect [-Wunused-value] i; ^ + for y in 98 11 17 + gcc -S -Wall -Wextra -Wpedantic -std=c++11 t.C t.C: In function ‘void f()’: t.C:9:4: warning: statement has no effect [-Wunused-value] i; ^ + for y in 98 11 17 + gcc -S -Wall -Wextra -Wpedantic -std=c++17 t.C t.C: In function ‘void f()’: t.C:9:4: warning: statement has no effect [-Wunused-value] i; ^ Conversely, the test case from comment #5 is rejected in C++ 11 and later and accepted in C++ 98 mode: $ (set -x; cat t.C && for y in 98 11 17; do gcc -S -Wall -Wextra -Wpedantic -std=c++$y t.C; done) + cat t.C namespace N { int i; } int i; void foo() { for (int i=0; i<10; ++i) ; using namespace N; i; } + for y in 98 11 17 + gcc -S -Wall -Wextra -Wpedantic -std=c++98 t.C t.C: In function ‘void foo()’: t.C:12:5: warning: name lookup of ‘i’ changed i; ^ t.C:6:5: warning: matches this ‘i’ under ISO standard rules int i; ^ t.C:10:14: warning: matches this ‘i’ under old rules for (int i=0; i<10; ++i) ; ^ t.C:12:6: warning: statement has no effect [-Wunused-value] i; ^ + for y in 98 11 17 + gcc -S -Wall -Wextra -Wpedantic -std=c++11 t.C t.C: In function ‘void foo()’: t.C:12:5: error: reference to ‘i’ is ambiguous i; ^ t.C:6:5: note: candidates are: int i int i; ^ t.C:3:9: note: int N::i int i; ^ + for y in 98 11 17 + gcc -S -Wall -Wextra -Wpedantic -std=c++17 t.C t.C: In function ‘void foo()’: t.C:12:5: error: reference to ‘i’ is ambiguous i; ^ t.C:6:5: note: candidates are: int i int i; ^ t.C:3:9: note: int N::i int i; ^