[Bug c++/61478] New: wrong handling of variable scopes inside for loop
mkrasowski at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Jun 11 15:22:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61478
Bug ID: 61478
Summary: wrong handling of variable scopes inside for loop
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mkrasowski at gmail dot com
Hi,
the following fails to compile (as expected):
void foo()
{
for(int i = 0; i < 10; i++) {
double i = 11;
}
}
int main() {
foo();
return 0;
}
with the following error:
gcc1.cc: In function 'void foo()':
gcc1.cc:6:16: error: redeclaration of 'double i'
double i = 11;
^
gcc1.cc:5:13: note: 'int i' previously declared here
for(int i = 0; i < 10; i++) {
However adding internal loop caused the above to compile i.e.
void foo()
{
for(int i = 0; i < 10; i++) {
for(int i = 0; i < 10; i++) {
int j = 2 * i;
}
double i = 11;
}
}
compiles with no warnings (if compiled with -Wall it will generate warning
about unused variables).
g++ 4.9.0 on x32_64 linux (latest arch linux), i.e.
% g++ --version
g++ (GCC) 4.9.0 20140604 (prerelease)
Regards,
marcin
More information about the Gcc-bugs
mailing list