explicit function template qualification
Jason Merrill
jason@cygnus.com
Sun Sep 28 13:12:00 GMT 1997
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
More information about the Gcc
mailing list