This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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


> 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 14.5.5.2, [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.

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

Regards,
Martin

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]