This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Bug (?) in namespaces and overloading resolution
- To: njs3 at doc dot ic dot ac dot uk
- Subject: Re: Bug (?) in namespaces and overloading resolution
- From: "Martin v. Loewis" <loewis at informatik dot hu-berlin dot de>
- Date: Tue, 23 Jun 1998 22:26:39 +0200
- CC: egcs-bugs at cygnus dot com
- References: <E0yoFVH-0000Ma-00@oak67.doc.ic.ac.uk>
> 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