c++/10852: Old for-scoping rules improperly used?
derrick@cco.caltech.edu
derrick@cco.caltech.edu
Mon May 19 08:37:00 GMT 2003
>Number: 10852
>Category: c++
>Synopsis: Old for-scoping rules improperly used?
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Mon May 19 07:46:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Derrick Bass
>Release: gcc-3.3
>Organization:
>Environment:
>Description:
I think this is a bug in g++; but there is always the possibility that it is a bug in my understanding of C++. In the following code gcc assumes that the variable i at the end of function is the same as in the for loop and produces the following error:
nstest.cc: In function `void f()':
nstest.cc:9: error: name lookup of `i' changed for new ISO `for' scoping
nstest.cc:6: error: using obsolete binding at `i'
I think it should use the variable i from inside the namespace and quit complaining, but as I said, I may just be misunderstanding C++ arcana.
Here's the sample code...
namespace X {
int i;
}
void f() {
for (int i=0; i<10; ++i)
;
using namespace X;
i;
}
>How-To-Repeat:
>Fix:
Workaround is to replace "using namespace X" with "using X::i"
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list