|
962 | 962 | A \grammarterm{template-id} that names an alias template
|
963 | 963 | specialization is a \grammarterm{type-name}.
|
964 | 964 |
|
| 965 | +\pnum |
| 966 | +A \grammarterm{template-id} is \defnx{valid}{\idxgram{template-id}!valid} if |
| 967 | +\begin{itemize} |
| 968 | +\item |
| 969 | + there are at most as many arguments as there are parameters |
| 970 | + or a parameter is a template parameter pack\iref{temp.variadic}, |
| 971 | + |
| 972 | +\item |
| 973 | + there is an argument for each non-deducible non-pack parameter |
| 974 | + that does not have a default \grammarterm{template-argument}, |
| 975 | + |
| 976 | +\item |
| 977 | + each \grammarterm{template-argument} matches the corresponding |
| 978 | + \grammarterm{template-parameter}\iref{temp.arg}, |
| 979 | + |
| 980 | +\item |
| 981 | + substitution of each template argument into the following |
| 982 | + template parameters (if any) succeeds, and |
| 983 | + |
| 984 | +\item |
| 985 | + if the \grammarterm{template-id} is non-dependent, |
| 986 | + the associated constraints are satisfied as specified in the next paragraph. |
| 987 | +\end{itemize} |
| 988 | +A \grammarterm{simple-template-id} shall be valid unless it names a |
| 989 | +function template specialization\iref{temp.deduct}. |
| 990 | +\begin{example} |
| 991 | +\begin{codeblock} |
| 992 | +template<class T, T::type n = 0> class X; |
| 993 | +struct S { |
| 994 | + using type = int; |
| 995 | +}; |
| 996 | +using T1 = X<S, int, int>; // error: too many arguments |
| 997 | +using T2 = X<>; // error: no default argument for first template parameter |
| 998 | +using T3 = X<1>; // error: value \tcode{1} does not match type-parameter |
| 999 | +using T4 = X<int>; // error: substitution failure for second template parameter |
| 1000 | +using T5 = X<S>; // OK |
| 1001 | +\end{codeblock} |
| 1002 | +\end{example} |
| 1003 | + |
965 | 1004 | \pnum
|
966 | 1005 | When the \grammarterm{template-name}
|
967 | 1006 | of a \grammarterm{simple-template-id}
|
|
5092 | 5131 | declared with a type
|
5093 | 5132 | that contains a placeholder type\iref{dcl.spec.auto},
|
5094 | 5133 |
|
| 5134 | +\item |
| 5135 | +an |
| 5136 | +\grammarterm{identifier} |
| 5137 | +associated by name lookup with |
| 5138 | +a variable declared with a type that contains a placeholder type\iref{dcl.spec.auto} |
| 5139 | +where the initializer is type-dependent, |
| 5140 | + |
5095 | 5141 | \item
|
5096 | 5142 | an \grammarterm{identifier} associated by name lookup with one or more
|
5097 | 5143 | declarations of member functions of the current instantiation declared
|
|
7026 | 7072 | \end{example}
|
7027 | 7073 |
|
7028 | 7074 | \pnum
|
7029 |
| -When an explicit template argument list is specified, if the template |
7030 |
| -arguments are not compatible with the template parameter list or do |
7031 |
| -not result in a valid function type as described below, type |
7032 |
| -deduction fails. Specifically, the following steps are performed when |
7033 |
| -evaluating an explicitly specified template argument list with respect |
7034 |
| -to a given function template: |
7035 |
| -\begin{itemize} |
7036 |
| -\item If the specified template arguments do not match the template |
7037 |
| -parameters in |
7038 |
| -kind (i.e., type, non-type, template), or if there |
7039 |
| -are more arguments than there are parameters |
7040 |
| -and no parameter is a template parameter pack, or if there is not |
7041 |
| -an argument for each non-pack parameter, |
7042 |
| -type deduction fails. |
7043 |
| - |
7044 |
| -\item If any non-type argument does not match the type of the |
7045 |
| -corresponding non-type |
7046 |
| -template parameter, and is not convertible to the type of the |
7047 |
| -corresponding non-type parameter as specified in~\ref{temp.arg.nontype}, |
| 7075 | +When an explicit template argument list is specified, if the |
| 7076 | +given \grammarterm{template-id} is not valid\iref{temp.names}, |
7048 | 7077 | type deduction fails.
|
7049 |
| - |
7050 |
| -\item The specified template argument values are substituted for the |
| 7078 | +Otherwise, the specified template argument values are substituted for the |
7051 | 7079 | corresponding template parameters as specified below.
|
7052 |
| -\end{itemize} |
7053 | 7080 |
|
7054 | 7081 | \pnum
|
7055 | 7082 | After this substitution is performed, the function parameter type
|
|
7146 | 7173 | inside \tcode{sizeof}, \tcode{decltype}, and other contexts that allow non-constant
|
7147 | 7174 | expressions. The substitution proceeds in lexical order and stops when
|
7148 | 7175 | a condition that causes deduction to fail is encountered.
|
| 7176 | +If substitution into different declarations of the same function template would |
| 7177 | +cause template instantiations to occur in a different order or not at all, |
| 7178 | +the program is ill-formed; no diagnostic required. |
7149 | 7179 | \begin{note}
|
7150 | 7180 | The equivalent substitution in exception specifications is
|
7151 | 7181 | done only when the \grammarterm{noexcept-specifier} is instantiated,
|
|
7159 | 7189 | template <class T> void f(...) { }
|
7160 | 7190 | template <class T> auto g(typename A<T>::X) -> typename T::X;
|
7161 | 7191 | template <class T> void g(...) { }
|
| 7192 | +template <class T> typename T::X h(typename A<T>::X); |
| 7193 | +template <class T> auto h(typename A<T>::X) -> typename T::X; // redeclaration |
| 7194 | +template <class T> void h(...) { } |
7162 | 7195 |
|
7163 |
| -void h() { |
| 7196 | +void x() { |
7164 | 7197 | f<int>(0); // OK, substituting return type causes deduction to fail
|
7165 | 7198 | g<int>(0); // error, substituting parameter type instantiates \tcode{A<int>}
|
| 7199 | + h<int>(0); // ill-formed, no diagnostic required |
7166 | 7200 | }
|
7167 | 7201 | \end{codeblock}
|
7168 | 7202 | \end{example}
|
|
0 commit comments