This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/10437: "using namespace" at global scope creates incorrect code
- From: bangerth at dealii dot org
- To: dean at foster dot net, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org
- Date: 21 Apr 2003 15:06:07 -0000
- Subject: Re: c++/10437: "using namespace" at global scope creates incorrect code
- Reply-to: bangerth at dealii dot org, dean at foster dot net, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
Synopsis: "using namespace" at global scope creates incorrect code
State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Mon Apr 21 15:06:06 2003
State-Changed-Why:
I don't think this is a bug. After quite some reducing,
your code looks like this:
---------------------------
struct X {
int operator-(const X& it);
};
template <class T>
struct Y {
typedef typename T::SOME_TYPE SOME_TYPE;
typedef int type;
};
#ifdef BUG
template <class T> typename Y<T>::type operator-(T,T);
#endif
int x = X() - X();
-----------------------------
(I replaced your using directive by the conditional
statement -- both just bring into visibility the
operator-.)
What happens is that in the minus statement (which was
inside a std:: function in your example), both possible
operator- are considered, i.e. the member function and
the global one. The global one requires instantiation
of Y, at which point we realize that X::SOME_TYPE does
not exist:
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ -c x.cc -DBUG
x.cc: In instantiation of `Y<X>':
x.cc:15: instantiated from here
x.cc:7: error: no type named `SOME_TYPE' in `struct X'
Tracing back where this happens in your code is a little
more complicated, but I guess this is what happens -- you
try to use __gnu_cxx::normal_iterator::const_iterator
when bringing into scope the function in the namespace,
but this const_iterator doesn't exist.
Wolfgang
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10437