|
7596 | 7596 |
|
7597 | 7597 | When all template arguments have been deduced or obtained from
|
7598 | 7598 | default template arguments, all uses of template parameters in
|
7599 |
| -the template parameter list of the template and the function type |
| 7599 | +the template parameter list of the template |
7600 | 7600 | are replaced with the corresponding deduced
|
7601 | 7601 | or default argument values. If the substitution results in an
|
7602 | 7602 | invalid type, as described above, type deduction fails.
|
7603 | 7603 | If the function template has associated constraints\iref{temp.constr.decl},
|
7604 | 7604 | those constraints are checked for satisfaction\iref{temp.constr.constr}.
|
7605 | 7605 | If the constraints are not satisfied, type deduction fails.
|
| 7606 | +In the context of a function call, if type deduction has not yet failed, then |
| 7607 | +for those function parameters for which the function call has arguments, |
| 7608 | +each function parameter with a type that was non-dependent |
| 7609 | +before substitution of any explicitly-specified template arguments |
| 7610 | +is checked against its corresponding argument; |
| 7611 | +if the corresponding argument cannot be implicitly converted |
| 7612 | +to the parameter type, type deduction fails. |
| 7613 | +\begin{note} |
| 7614 | +Overload resolution will check the other parameters, including |
| 7615 | +parameters with dependent types in which |
| 7616 | +no template parameters participate in template argument deduction and |
| 7617 | +parameters that became non-dependent due to substitution of |
| 7618 | +explicitly-specified template arguments. |
| 7619 | +\end{note} |
| 7620 | +If type deduction has not yet failed, then |
| 7621 | +all uses of template parameters in the function type are |
| 7622 | +replaced with the corresponding deduced or default argument values. |
| 7623 | +If the substitution results in an invalid type, as described above, |
| 7624 | +type deduction fails. |
| 7625 | +\begin{example} |
| 7626 | +\begin{codeblock} |
| 7627 | +template <class T> struct Z { |
| 7628 | + typedef typename T::x xx; |
| 7629 | +}; |
| 7630 | +template <class T> concept C = requires { typename T::A; }; |
| 7631 | +template <C T> typename Z<T>::xx f(void *, T); // \#1 |
| 7632 | +template <class T> void f(int, T); // \#2 |
| 7633 | +struct A {} a; |
| 7634 | +struct ZZ { |
| 7635 | + template <class T, class = typename Z<T>::xx> operator T *(); |
| 7636 | + operator int(); |
| 7637 | +}; |
| 7638 | +int main() { |
| 7639 | + ZZ zz; |
| 7640 | + f(1, a); // OK, deduction fails for \#1 because there is no conversion from \tcode{int} to \tcode{void*} |
| 7641 | + f(zz, 42); // OK, deduction fails for \#1 because \tcode{C<int>} is not satisfied |
| 7642 | +} |
| 7643 | +\end{codeblock} |
| 7644 | +\end{example} |
7606 | 7645 |
|
7607 | 7646 | \pnum
|
7608 | 7647 | At certain points in the template argument deduction process it is necessary
|
|
8160 | 8199 | \end{codeblock}
|
8161 | 8200 | \end{example}
|
8162 | 8201 |
|
8163 |
| -\pnum |
8164 |
| -If deduction succeeds for all parameters that contain |
8165 |
| -\grammarterm{template-parameter}{s} that participate in template argument |
8166 |
| -deduction, and all template arguments are explicitly specified, deduced, |
8167 |
| -or obtained from default template arguments, remaining parameters are then |
8168 |
| -compared with the corresponding arguments. For each remaining parameter |
8169 |
| -\tcode{P} with a type that was non-dependent before substitution of any |
8170 |
| -explicitly-specified template arguments, if the corresponding argument |
8171 |
| -\tcode{A} cannot be implicitly converted to \tcode{P}, deduction fails. |
8172 |
| -\begin{note} |
8173 |
| -Parameters with dependent types in which no \grammarterm{template-parameter}{s} |
8174 |
| -participate in template argument deduction, and parameters that became |
8175 |
| -non-dependent due to substitution of explicitly-specified template arguments, |
8176 |
| -will be checked during overload resolution. |
8177 |
| -\end{note} |
8178 |
| -\begin{example} |
8179 |
| -\begin{codeblock} |
8180 |
| -template <class T> struct Z { |
8181 |
| - typedef typename T::x xx; |
8182 |
| -}; |
8183 |
| -template <class T> typename Z<T>::xx f(void *, T); // \#1 |
8184 |
| -template <class T> void f(int, T); // \#2 |
8185 |
| -struct A {} a; |
8186 |
| -int main() { |
8187 |
| - f(1, a); // OK, deduction fails for \#1 because there is no conversion from \tcode{int} to \tcode{void*} |
8188 |
| -} |
8189 |
| -\end{codeblock} |
8190 |
| -\end{example} |
8191 |
| - |
8192 | 8202 | \rSec3[temp.deduct.funcaddr]{Deducing template arguments taking the address of a function template}
|
8193 | 8203 |
|
8194 | 8204 | \pnum
|
|
0 commit comments