This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
g++ 2.95.2 accepts an ambiguous template overload
- To: "gcc bug list" <gcc-bugs at gcc dot gnu dot org>
- Subject: g++ 2.95.2 accepts an ambiguous template overload
- From: " " <sebor at my-Deja dot com>
- Date: Sun, 05 Mar 2000 20:32:59 -0800
- Cc: "John Pedretti" <pedretti at roguewave dot com>
- Organization: My Deja Email (http://www.my-deja.com:80)
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.