[C++ PATCH]: Incomplete explicit args

Mark Mitchell mark@codesourcery.com
Tue Jul 29 22:23:00 GMT 2003


On Tue, 2003-07-29 at 11:12, Jason Merrill wrote:
> On 28 Jul 2003 12:22:07 -0700, Mark Mitchell <mark@codesourcery.com> wrote:
> 
> > The issue I was thinking about (which may be different than the
> > situation you had in mind) comes up when trying to determine which of
> > two function templates is more specialized.  Consider:
> >
> >   template <typename T> void f(T, typename A<T>::X);
> >   template <typename T> void f(T*, int);
> >
> > Now, we're supposed to deduce the parameters for the first template from
> > the argument list of the second.  From the "T*" parameter in the second,
> > we conclude that the "T" argument for the first must be "T*".  The
> > second argument for the first template is a non-deduced context, so
> > nothing more happens.
> >
> > But then, the passage I quoted above kicks in: we're supposed to make
> > the "T => T*" transformation and check to see if any invalid types are
> > formed.  That's difficult because we still have template parameters
> > flying around.
> 
> Yes; A<T>::X becomes A<T*>::X, which is still dependent, so the
> substitution is OK regardless of what A looks like.

So say you. :-)  I don't see anything in the standard that says one way
or the other, but what you say makes sense.
 
> 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).
> 
> We can't actually test whether A<T*>::X is an exact match for int; I think
> the right thing to do is to accept it, but there should probably be a core
> issue created to add the appropriate words.

Indeed.

> > I think that the best solution would be to say that in the determining
> > of which of two templates is more specialized, you do not have to
> > perform the substitution phase I quoted above.  If the more-specialized
> > template turns out to involve invalid types, that's an error when it is
> > actually used.  I believe that this would avoid *ever* having to make a
> > substitution where the new values involve template parameters.
> 
> This would also result in choosing a template which cannot be instantiated
> over one which is less specialized, but can be instantiated.

I'm sorry; I meant to make clear that I foresaw the consequence you
state, and that I don't see that as a particularly bad thing.

However, if you, Nathan, and the standard all think otherwise, I guess
that's OK with me...

Nathan, I agree that, given this interpretation, the thing to do is to
build a new SCOPE_REF in tsubst_qualified_id, and pass it back.

Thanks,

-- 
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com



More information about the Gcc-patches mailing list