This is the mail archive of the gcc-bugs@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 Friend Weirdness


> 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


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