g++ 2.95.2 cannot resolve a return-type template function overload

Fri Jan 28 09:13:00 GMT 2000

On Fri, 28 Jan 2000 10:46:18   Martin v. Loewis wrote:
>> the program below gives an error with g++ 2.95.2. I believe since
>> the second foo<>() matches exactly it is a "better match" than the
>> first foo<>(). The program compiles fine with edg 2.42.
>Thanks for your bug report. I believe this is an error in your code
>(and a bug in edg, unless it is diagnosed as an extension).
>First, template argument deduction succeeds for both templates, so
>they are both candidates. The conversion sequences for the arguments
>are identical, so 'partial ordering' must be considered.
>Here's the relevant text from, [temp.func.order]
># The transformation used is:
># - For each type template parameter, synthesize a unique type and
>#   substitute that for each occurrence of that parameter in the
>#   function parameter list, or for a template conversion function, in
>#   the return type.
># - For each non-type template parameter, [we don't have any]
># - For each template template parameter, [we don't have any]
># Using the transformed function parameter list, perform argument
># deduction against the other function template. The transformed
># template is at least as specialized as the other if, and only if,
># the deduction succeeds and the deduced parameter types are an exact
># match (so the deduction does not rely on implicit conversions).
>So we choose the first template, and synthesize unique types t, and
>u. We perform template argument deduction of foo(u) against the other
>template. This fails, since we cannot deduce a type for T.
>Now, the other way round. We synthesize a unique type t, and perform
>deduction of foo(int) against the other template. This gives us U=int,
>but T cannot be determined.

But T, which is the only parameter of the second template, is explicitly specified in the call to foo<int>(0), so the second foo specialized on int with an int argument _is_ an exact match for the call. Otherwise there's no way to call the second foo.


>So neither template is at least as specialized as the other, and the
>call is ambiguous.

--== Sent via Deja.com http://www.deja.com/ ==--
Share what you know. Learn what you don't.

More information about the Gcc-bugs mailing list