This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Incorrect overload resolution with template constructor
- To: lalle at sics dot se
- Subject: Re: Incorrect overload resolution with template constructor
- From: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Date: Thu, 11 May 2000 07:58:58 +0200
- CC: gcc-bugs at gcc dot gnu dot org
- References: <u6z1z4ejn67.fsf@saruman.sics.se>
> I expeceted the following code to use the operator+ supplied with B.
> However, the compiler tries to use the template constructor for C, and
> considers C's operator+ functions as equal fits. It shouldn't, as they
> have template arguments. Note that the ordinary constructors C(A) and
> C(B) are correctly not considered.
Thanks for your bug report. This is not a bug in the compiler, but in
your code. The compiler sees all three operator+ declarations. For the
templates, it performs template argument deduction and gets
class C operator +<B>(const C &, const B &)
class C operator +<A>(const A &, const C &)
It compares each of these signatures with the non-template version,
namely
struct B operator +(const B &, const B &)
None of these functions is better then any other. They all have an
exact match in one argument and a user-defined conversion sequence in
the other, so the call is ambiguous.
If you question this line of reasoning, please discuss it in one of
the public C++ fora first, eg. comp.lang.c++.moderated, or
comp.std.c++.
Regards,
Martin