This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Template mangling bug in egcs-2.90.16
- To: Tom Kunert <tom at rp168 dot urz dot tu-dresden dot de>
- Subject: Re: Template mangling bug in egcs-2.90.16
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 17 Nov 1997 14:55:49 -0200
- Cc: Andreas Schwab <schwab at issan dot informatik dot uni-dortmund dot de>, egcs at cygnus dot com
- References: <Pine.LNX.3.96.971117163642.10130A-100000@rp168.urz.tu-dresden.de>
Tom Kunert writes:
> On 17 Nov 1997, Andreas Schwab wrote:
>> In the following example the function f1 is referenced under the name
>> "f1(int)", but it should be "A<int> f1<int>(int)".
>>
>> $ cat template.cc
>> template <class X>
>> struct A
>> {
>> X x;
>> friend A f1 (X);
>> };
>>
>> template <class X> A<X> f1 (X) { A<X> a; return a; }
>> template <class X> A<X> f2 (const A<X>& a) { return f1 (a.x); }
> Obviously the compiler sees two different functions f1(1)
But it shouldn't. A f1(int) is only visible inside the scope of
A<int>, because it is not declared in the global namespace. Thus, in
the scope of f2<int>(A<int> const&), the name f1 must resolve to the
template instantiation f1<int>(int), not to the non-template function
f1(int).
> The question is, whether the compiler is allowed to regard the friend
> declaration as an ordinary function.
It must. There's a bug in the CD2, fixed in a later edition of the
DWP (now Standard!). The relevant sections are [temp.inject] and
[basic.lookup.koenig]
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil