Skip to content

Commit 7ee5245

Browse files
burblebeetkoeppe
authored andcommitted
CWG2369 Ordering between constraints and substitution
1 parent 8cff053 commit 7ee5245

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
@@ -7596,13 +7596,52 @@
75967596

75977597
When all template arguments have been deduced or obtained from
75987598
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
76007600
are replaced with the corresponding deduced
76017601
or default argument values. If the substitution results in an
76027602
invalid type, as described above, type deduction fails.
76037603
If the function template has associated constraints\iref{temp.constr.decl},
76047604
those constraints are checked for satisfaction\iref{temp.constr.constr}.
76057605
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}
76067645

76077646
\pnum
76087647
At certain points in the template argument deduction process it is necessary
@@ -8160,35 +8199,6 @@
81608199
\end{codeblock}
81618200
\end{example}
81628201

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-
81928202
\rSec3[temp.deduct.funcaddr]{Deducing template arguments taking the address of a function template}
81938203

81948204
\pnum

0 commit comments

Comments
 (0)