warning that warns about iso compliant code

Burlen Loring burlen.loring@kitware.com
Thu May 1 13:21:00 GMT 2008


Hi all, can anyone comment on this warning? I think that it might 
loosely be classified as a "bug" in the compiler because it warns both 
about the correct code and the incorrect code. There is more detail 
below. Given the fact that I have almost zero formal cs training, I 
would like to get some comments from the more experienced guys, if 
possible thanks. Burlen

for code such as:

int main()
{
int nToProcess=0;
for (int i=0; i<nToProcess; ++i)
   {
   int nComp=0;
   for (int i=0; i<nComp; ++i)
     {
     int j=i;
     }
     int q=i;
   }
return 0;
}

I have the following warnings:

testNetsted.cpp: In function ‘int main()’:
testNetsted.cpp:11: warning: name lookup of ‘i’ changed
testNetsted.cpp:4: warning: matches this ‘i’ under ISO standard rules
testNetsted.cpp:7: warning: matches this ‘i’ under old rules

To me it seems the compiler should not warn about code that follows the
ISO standard rules. However, it would be nice if the compiler warned 
about the case that didn't follow the standard. I personally like to 
hide the outer variables because it documents the fact that a particular 
loop does not use that variable. Am I just being silly and I should use 
different index variable name for all of my nested loops,even when there 
are no dependencies?




More information about the Gcc-help mailing list