This is the mail archive of the gcc@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: Template mangling bug in egcs-2.90.16


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


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