This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
suspicious overload resolution of function templates
- To: gcc-bugs at gcc dot gnu dot org
- Subject: suspicious overload resolution of function templates
- From: Ewgenij Gawrilow <gawrilow at math dot TU-Berlin dot DE>
- Date: Mon, 6 Mar 2000 17:40:05 +0100 (MET)
It's probably more a question than a bug report: can anybody be so patient to
explain me why in the following constellation the template #1 is being chosen
in both calls? Anyhow, so does the gcc 2.95.2.
template <class X> class A { };
template <class X> class B : public A<X> { };
class C { };
class D : public C { };
// #1
template <class X> void f(X x);
// #2
template <class X> void f(const A<X>& x);
// #3
void f(const C& x);
int main()
{
B<int> b;
D d;
f(b), f(d);
return 0;
}
I thought, #2 is more specialized than #1, and #3 should be moreover preferred
as being a non-template.
If the compiler behaves correctly, how can I otherwise manage to prevent the
"last resort" specialization (#1) from shadowing the others (#2 and #3) which
should handle objects from entire hierarchies of classes, not just of the base
class?
I'd very appreciate any plausible advices.
With best regards,
Ewgenij Gawrilow
Dept. of Mathematics, Technical University of Berlin