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]

g++ 2.95.2 accepts an ambiguous template overload


Hi,

the code below compiles (and resolves to the second foo<>()) with g++ 2.95.2. I'm not sure that this is the correct behavior - specifically, I don't see that the second foo<>() is more specialized than the first according to the partial ordering rules. Here's my reasoning:

For one template to be more specialized than the other it must be at least as specialized as the other and the other must not be as specialized as the first (14.5.5.2, p5).

Following the algorithm in 14.5.5.2, p2-5, and considering each template in turn without regard to the actual call:

1) synthesize a unique type, say U, substitute it for the template
   parameter and perform argument deduction against the other template
   for template <T> foo (T):
     substitute foo(U) -> deduce foo<U>(const U&), deduced type is U, no
     conversion required (identity conversion, 14.8.2.1, p3, bulet 1 applies)
     hence foo<T>(T) is at least as pecialized as foo<T>(const T&)

2) repeat 1) for the other template
   for template <T> foo (const T&):
      substitute foo(const U&) -> deduce foo<const U>(const U&) deduced
      type is const U (dropping top-level reference according to 14.8.2.1,
      p3), no conversion required (identity conversion)
      hence foo<T>(const T&) is at least as pecialized as foo<T>(T)

3) since each template is as specialized as the other, the call is
   ambiguous

I've discussed this with John Spicer of EDG who's of the opinion that the call is unambiguous: he doesn't think that  14.8.2.1, p3 should be considered in step 1 above.

I also talked to HP (aCC 3.14.10 rejects the call as ambiguous) and they follow the same line of reasoning as myself.

I believe that the partial ordering rules are underspecified and need to be clarified, however, I would appreciate your opinion before submitting an issue.

Thanks
Martin


template <class T>
int foo (T)
{
    return 0;
}

template <class T>
int foo (const T&)
{
    return 1;
}

int main ()
{
    return foo (int ());
}



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

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