Bug 14515 - bad interaction between using namespace and for loop variable
Summary: bad interaction between using namespace and for loop variable
Status: RESOLVED DUPLICATE of bug 10852
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-03-10 16:36 UTC by Christopher Eltschka
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Eltschka 2004-03-10 16:36:41 UTC
The following code gives an error when compiled without any options:

$ g++ bug.cc
bug.cc: In function `int main()':
bug.cc:14: error: name lookup of `i' changed for new ISO `for' scoping
bug.cc:8: error:   using obsolete binding at `i'

The preprocessed code:

# 1 "bug.cc"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "bug.cc"
namespace foo
{
  int i;
}

int main()
{
  for (int i=0; i<=10; ++i)
  {
  }

  {
    using namespace foo;
    i = 5;
  }
}

Since at the point of assignment, there is an accessible i (namely foo::i), it
should be used instead of trying to access the for loop variable (which isn't in
scope any more, as the error message correctly points out).

Configured with: ./configure --prefix=/psi/gcc-3.3
Comment 1 Andrew Pinski 2004-03-10 16:48:05 UTC
This is a dup of bug 10852.

*** This bug has been marked as a duplicate of 10852 ***