suspicious overload resolution of function templates

Ewgenij Gawrilow gawrilow@math.TU-Berlin.DE
Mon Mar 6 08:40:00 GMT 2000


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


More information about the Gcc-bugs mailing list