This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

scoping of declarations in loops and -Wshadow


Hi,

Consider the following C++ program:

int main()
{
        volatile int    j;
 
        for (int i = 0; i < 10; i++)
                j = i;  
 
#ifdef REDECLARE_I
        for (int i = 0; i < 10; i++)
                j = i;
#else
        for (i = 0; i < 10; i++)
                j = i;
#endif
}


One or other of the following warnings is bogus, I believe.

[njs3@cnet0000 ~]$ g++ -v
Reading specs from /homes/njs3/pub/egcs/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.08/specs
gcc version egcs-2.91.08 980214 (gcc-2.8.0 release)

[njs3@cnet0000 ~]$ g++ foo.c -Wall -Wshadow              
foo.c: In function `int main()':
foo.c:12: warning: name lookup of `i' changed for new ANSI `for' scoping
foo.c:5: warning:   using obsolete binding at `i'

[njs3@cnet0000 ~]$ g++ foo.c -Wall -Wshadow -DREDECLARE_I
foo.c: In function `int main()':
foo.c:9: warning: declaration of `i' shadows previous local

Surely they contradict each other?  I think the second one is in error.

Regards,

Niall Smart



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]