This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Bug (?) in namespaces and overloading resolution


> I've appended the code again so that we are definately talking about
> the same thing, its a while since I posted this.

[NOTE: I'd appreciate if somebody with good understanding of the C++
standard could verify my claims. Thanks]

Hi Niall,

I'm not too sure we talk about the same code. Comparing the sources
given in

http://www.cygnus.com/ml/egcs-bugs/1998-Jun/0298.html

and

http://www.cygnus.com/ml/egcs-bugs/1998-Jun/0455.html
(your last message)

I find several differences. Most notably, the first message is missing

namespace A{
  using B::operator<<;
}

which makes Koenig lookup find the operator. As a matter of fact, the
example given in your second message compiles fine for me with

GNU C++ version egcs-2.91.42 19980623 (gcc2 ss-980502 experimental)
(sparc-sun-solaris2.5.1) compiled by GNU C version 2.8.1

The first code you give is in error, even though there are global
using directives. The reason is non-obvious at the first glance: For
template instantiations, name lookup occurs in the namespace context
where the template was defined, not where it is instantiated. So when
instantiating C::operator<<<A::X>(C::Y&,A::X&) (HTML alert), the
unqualified lookup for operator<<(ostream&,A::X&) is performed in the
context of C. The operator template << inside C hides the global
operator(s) with the same name, so lookup only finds this template,
and the operator members of ostream.

The hiding is defined in [basic.scope.hiding]/1, and the example in
[namespace.def]/5 pretty much supports my interpretation.

Regards,
Martin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]