Skip to content

Commit efef313

Browse files
committed
CWG2369 Ordering between constraints and substitution
1 parent 6d7e613 commit efef313

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed

source/templates.tex

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7597,13 +7597,52 @@
75977597

75987598
When all template arguments have been deduced or obtained from
75997599
default template arguments, all uses of template parameters in
7600-
the template parameter list of the template and the function type
7600+
the template parameter list of the template
76017601
are replaced with the corresponding deduced
76027602
or default argument values. If the substitution results in an
76037603
invalid type, as described above, type deduction fails.
76047604
If the function template has associated constraints\iref{temp.constr.decl},
76057605
those constraints are checked for satisfaction\iref{temp.constr.constr}.
76067606
If the constraints are not satisfied, type deduction fails.
7607+
In the context of a function call, if type deduction has not yet failed, then
7608+
for those function parameters for which the function call has arguments,
7609+
each function parameter with a type that was non-dependent
7610+
before substitution of any explicitly-specified template arguments
7611+
is checked against its corresponding argument;
7612+
if the corresponding argument cannot be implicitly converted
7613+
to the parameter type, type deduction fails.
7614+
\begin{note}
7615+
Overload resolution will check the other parameters, including
7616+
parameters with dependent types in which
7617+
no template parameters participate in template argument deduction and
7618+
parameters that became non-dependent due to substitution of
7619+
explicitly-specified template arguments.
7620+
\end{note}
7621+
If type deduction has not yet failed, then
7622+
all uses of template parameters in the function type are
7623+
replaced with the corresponding deduced or default argument values.
7624+
If the substitution results in an invalid type, as described above,
7625+
type deduction fails.
7626+
\begin{example}
7627+
\begin{codeblock}
7628+
template <class T> struct Z {
7629+
typedef typename T::x xx;
7630+
};
7631+
template <class T> concept C = requires { typename T::A; };
7632+
template <C T> typename Z<T>::xx f(void *, T); // \#1
7633+
template <class T> void f(int, T); // \#2
7634+
struct A {} a;
7635+
struct ZZ {
7636+
template <class T, class = typename Z<T>::xx> operator T *();
7637+
operator int();
7638+
};
7639+
int main() {
7640+
ZZ zz;
7641+
f(1, a); // OK, deduction fails for \#1 because there is no conversion from \tcode{int} to \tcode{void*}
7642+
f(zz, 42); // OK, deduction fails for \#1 because \tcode{C<int>} is not satisfied
7643+
}
7644+
\end{codeblock}
7645+
\end{example}
76077646

76087647
\pnum
76097648
At certain points in the template argument deduction process it is necessary
@@ -8161,35 +8200,6 @@
81618200
\end{codeblock}
81628201
\end{example}
81638202

8164-
\pnum
8165-
If deduction succeeds for all parameters that contain
8166-
\grammarterm{template-parameter}{s} that participate in template argument
8167-
deduction, and all template arguments are explicitly specified, deduced,
8168-
or obtained from default template arguments, remaining parameters are then
8169-
compared with the corresponding arguments. For each remaining parameter
8170-
\tcode{P} with a type that was non-dependent before substitution of any
8171-
explicitly-specified template arguments, if the corresponding argument
8172-
\tcode{A} cannot be implicitly converted to \tcode{P}, deduction fails.
8173-
\begin{note}
8174-
Parameters with dependent types in which no \grammarterm{template-parameter}{s}
8175-
participate in template argument deduction, and parameters that became
8176-
non-dependent due to substitution of explicitly-specified template arguments,
8177-
will be checked during overload resolution.
8178-
\end{note}
8179-
\begin{example}
8180-
\begin{codeblock}
8181-
template <class T> struct Z {
8182-
typedef typename T::x xx;
8183-
};
8184-
template <class T> typename Z<T>::xx f(void *, T); // \#1
8185-
template <class T> void f(int, T); // \#2
8186-
struct A {} a;
8187-
int main() {
8188-
f(1, a); // OK, deduction fails for \#1 because there is no conversion from \tcode{int} to \tcode{void*}
8189-
}
8190-
\end{codeblock}
8191-
\end{example}
8192-
81938203
\rSec3[temp.deduct.funcaddr]{Deducing template arguments taking the address of a function template}
81948204

81958205
\pnum

0 commit comments

Comments
 (0)