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]

partial ordering of function templates


Hi,
this question concerns 14.5.5.2, where I think gcc is erroneously rejecting
a valid program -- but I'm not sure.

	template <typename T> void Foo (T *); //a
	template <typename T> void Foo (T &); //b

	void Baz (int *ptr)
	{
	  Foo (ptr);
	}

current/deduce.ii:6: call of overloaded `Foo(int*&)' is ambiguous
current/deduce.ii:1: candidates are: void Foo(T*) [with T = int]
current/deduce.ii:2:                 void Foo(T&) [with T = int*]

but I think the first choice is more specialized than the second. 14.5.5.2
tells us to take each choice in turn, synthesize a unique type for each
template type parameter into the function's parameter list and then try
type deduction using the other choice. The transformed template is at least
as specialized as the other if deduction succeeds and the deduced parameter
types are an exact match. In this case that gives us, with a unique type
called 'X'

a: Foo (T *) -> Foo (X *), using Foo (T &) deduce T to be X *, deduction succeeds.
b: Foo (T &) -> Foo (X &), using Foo (T *) deduction fails

so b is less specialized than a, and void Foo(T*) [with T = int] should
be selected

Am I forgetting something?

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org

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