c++/10852: Old for-scoping rules improperly used?

[email protected]
Newsgroups gmane.comp.gcc.prs
Message-ID <[email protected]>
>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:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.