public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* explicit function template qualification
@ 1997-09-28 13:12 Jason Merrill
  1997-10-02  9:47 ` Mumit Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 1997-09-28 13:12 UTC (permalink / raw)
  To: egcs, g++

I just checked in a patch from Mark to implement explicit specification of
template parameters to function templates.  In other words,

  template<class T>
  T min (T a, T b) { return a<b?a:b; }

  main ()
  {
    return min<int>(5, 8.0);
  }

A couple of side effects that may bite you:

1) Mangling of template instantiations now depends on the template they
   came from; in particular, template instantiations are no longer mangled
   like a non-template function.

2) Guiding decls are no longer supported.  So code like

     struct A {
       friend int operator== (const A&, const A&);
       A (int) { }
     };

     template <class T> int
     operator== (const T&, const T&)
     {
       return 0;
     }

     main ()
     {
       A a (1);
       return a == 1;
     }

   will now fail with an undefined symbol, because the friend refers to a
   normal function, not a template instantiation.  The complex and iomanip
   classes in libstdc++, for instance, had to be changed.  If the friend
   really needs to be a friend, you can add <> after the declarator (so
   operator==<>, in this example) to make it refer to a template
   instantiation.  If you had the friend decl in a template for overloading
   purposes, you're out of luck; you'll need to define any forwarding
   functions.  This is the way the language works now, sorry.

Both of these side effects can be reverted with -fguiding-decls, but that
will cause mangling clashes in some cases of explicit qualification, and
should not be used with new code.

Thanks again, Mark!

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1997-10-02 13:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-09-28 13:12 explicit function template qualification Jason Merrill
1997-10-02  9:47 ` Mumit Khan
1997-10-02 13:28   ` Mark Mitchell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).