This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Template Friend Weirdness
- To: mcq at cs dot utah dot edu
- Subject: Re: Template Friend Weirdness
- From: "Martin v. Loewis" <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Sat, 10 Jul 1999 12:16:32 +0200
- CC: egcs-bugs at egcs dot cygnus dot com
- References: <199907081828.MAA02567@epic.cs.utah.edu>
> In egcs-19990629 on a i386 Linux-2.2.10 / glibc-2.1.1 machine, it
> says:
[...]
> n.C:15: warning: friend declaration `void TFunc(SomeClass<T> &)'
> n.C:15: warning: declares a non-template function
> n.C:15: warning: (if this is not what you intended, make sure
> n.C:15: warning: the function template has already been declared,
> n.C:15: warning: and add <> after the function name here)
> n.C:15: warning: -Wno-non-template-friend disables this warning.
[...]
> Adding the <> as the warning suggests produces a working compile in egcs, but
> breaks all the other compilers (parse errors). I'm happy to ignore the
> warning or turn it off with the indicated switch.
The warning is there for a reason. If you leave your original code, it
expects that there is a new global friend function for each
instantiation.
> The actual bug appears to be that the global template f'n never gets
> instantiated even though it's quite clearly called from main().
This is not a bug. If you leave it as it was, you have to define a
function
void TFunc(SomeClass<int>&);
which is not a template instantiation.
> This compiles and runs fine on Microsoft C++, Borland C++ for
> Windows and the SGI MIPSpro C++ copmiler (the current 7.30).
Then those compilers are all in error. If you want to make a bug
report, you can refer them to section 14.5.3, [temp.friend]/1 of the
C++ standard. Perhaps you could try whether they accept
friend void TFunc<T>(SomeClass<T>&);
first, which is the example explicitly given in the standard.
Regards,
Martin