PATCH for friend/template/inline link-failure

Mark Mitchell
Tue Sep 1 22:21:00 GMT 1998

>>>>> "Alexandre" == Alexandre Oliva <> writes:

    Alexandre> Mark Mitchell <> writes:

    >> template <class P1> struct S1 { struct SS1 { }; friend void Foo
    >> (const SS1& ss1) { } };

    Alexandre> In this case, I think Foo is a non-template function,
    Alexandre> so it must be explicitly defined for each type
    Alexandre> S1<P1>::SS1.  A template definition won't do.

You're right, and, then again, you're not. :-)


  template <class T> struct S { friend void f(T) {} };

There is presently no global `f'.  After:

  template struct S<int>;

There is now a global function `void f(int)'.  It is not a template
instance, but it does have a definition.  In many ways it is *like* a
template instantiation, so far as the compiler is concerned, but it's
just a non-template function so far as the language is concerned.  If
you did:

  S<double> s2;

you'd now have `void f(double)' as well.

Mark Mitchell
Mark Mitchell Consulting

More information about the Gcc-patches mailing list