This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

Re: [C++ PATCH]: Incomplete explicit args


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.

However, 14.5.5.2 says,

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.

> 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.

Jason


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