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: Andreas Schwab <schwab at issan dot informatik dot uni-dortmund dot de>
- Subject: Re: Template mangling bug in egcs-2.90.16
- From: Tom Kunert <tom at rp168 dot urz dot tu-dresden dot de>
- Date: Mon, 17 Nov 1997 17:12:01 +0100 (MET)
- cc: egcs at cygnus dot com
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); }
>
> template A<int> f1 (int);
> template A<int> f2 (const A<int>&);
> $ gcc -c template.cc
> $ nm -C template.o
> 00000000 ? __FRAME_BEGIN__
> U f1(int)
> 00000000 T A<int> f1<int>(int)
> 00000012 T A<int> f2<int>(A<int> const &)
> 00000000 t gcc2_compiled.
Obviously the compiler sees two different functions f1(1) : One is the
instantiation of a template and one is an ordinary function. According
to the DWP these functions can coexist, the overload-resolution rules
prefer the normal function.
The friend declaration in the example is regarded as function, not as
template, so it is undefined (U). Any call to f1(int) will result in a
linker error: f1(int) not defined.
The question is, whether the compiler is allowed to regard the friend
declaration as an ordinary function. I think, this should be a function
template and there is a bug in egcs. (See DWP Nov. 96, 14.3.5)
Thomas Kunert <tom@rp168.urz.tu-dresden.de>