Skip to content

Commit 3f3c5c9

Browse files
burblebeetkoeppe
authored andcommitted
CWG2918 Consideration of constraints for address of overloaded function
1 parent 521364d commit 3f3c5c9

File tree

3 files changed

+102
-26
lines changed

3 files changed

+102
-26
lines changed

source/compatibility.tex

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,38 @@
122122
\end{codeblock}
123123
\end{example}
124124

125+
\diffref{temp.deduct.call}
126+
\change
127+
Template argument deduction from overload sets succeeds in more cases.
128+
\rationale
129+
Allow consideration of constraints to disambiguate overload sets
130+
used as parameters in function calls.
131+
\effect
132+
Valid \CppXXIII{} code may become ill-formed.
133+
\begin{example}
134+
\begin{codeblock}
135+
template <typename T>
136+
void f(T &&, void (*)(T &&));
137+
138+
void g(int &); // \#1
139+
inline namespace A {
140+
void g(short &&); // \#2
141+
}
142+
inline namespace B {
143+
void g(short &&); // \#3
144+
}
145+
146+
void q() {
147+
int x;
148+
f(x, g); // ill-formed; previously well-formed, deducing \tcode{T = int\&}
149+
}
150+
\end{codeblock}
151+
There is no change to the applicable deduction rules for
152+
the individual \tcode{g} candidates:
153+
Type deduction from \#1 does not succeed;
154+
type deductions from \#2 and \#3 both succeed.
155+
\end{example}
156+
125157
\rSec2[diff.cpp23.library]{\ref{library}: library introduction}
126158

127159
\diffref{headers}

source/overloading.tex

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,19 +1795,8 @@
17951795

17961796
\item
17971797
$\tcode{F}_1$ and $\tcode{F}_2$ are non-template functions and
1798-
\begin{itemize}
1799-
\item
1800-
they have the same non-object-parameter-type-lists\iref{dcl.fct}, and
1801-
\item
1802-
if they are member functions, both are direct members of the same class, and
1803-
\item
1804-
if both are non-static member functions,
1805-
they have the same types for their object parameters, and
1806-
\item
1807-
$\tcode{F}_1$ is more constrained than $\tcode{F}_2$
1808-
according to the partial ordering of constraints described in
1809-
\ref{temp.constr.order}
1810-
\end{itemize}
1798+
$\tcode{F}_1$ is more partial-ordering-constrained than
1799+
$\tcode{F}_2$\iref{temp.constr.order}
18111800
\begin{example}
18121801
\begin{codeblock}
18131802
template <typename T = int>
@@ -3117,6 +3106,9 @@
31173106
a non-type
31183107
\grammarterm{template-parameter}\iref{temp.arg.nontype}.
31193108
\end{itemize}
3109+
If the target type contains a placeholder type,
3110+
placeholder type deduction is performed\iref{dcl.type.auto.deduct}, and
3111+
the remainder of this subclause uses the target type so deduced.
31203112
The \grammarterm{id-expression} can be preceded by the \tcode{\&} operator.
31213113
\begin{note}
31223114
Any redundant set of parentheses surrounding the function name is
@@ -3169,10 +3161,8 @@
31693161
\tcode{F0}
31703162
is eliminated if the set contains a second
31713163
non-template function that
3172-
is more constrained than
3173-
\tcode{F0}
3174-
according to
3175-
the partial ordering rules of \ref{temp.constr.order}.
3164+
is more partial-ordering-constrained than
3165+
\tcode{F0}\iref{temp.constr.order}.
31763166
Any given
31773167
function template specialization
31783168
\tcode{F1}
@@ -3208,8 +3198,9 @@
32083198
with type
32093199
\tcode{int(...)}
32103200
has been declared, and not because of any ambiguity.
3211-
For another example,
3201+
\end{example}
32123202

3203+
\begin{example}
32133204
\begin{codeblock}
32143205
struct X {
32153206
int f(int);
@@ -3226,6 +3217,21 @@
32263217
\end{codeblock}
32273218
\end{example}
32283219

3220+
\begin{example}
3221+
\begin{codeblock}
3222+
template<bool B> struct X {
3223+
void f(short) requires B;
3224+
void f(long);
3225+
template<typename> void g(short) requires B;
3226+
template<typename> void g(long);
3227+
};
3228+
void test() {
3229+
&X<true>::f; // error: ambiguous; constraints are not considered
3230+
&X<true>::g<int>; // error: ambiguous; constraints are not considered
3231+
}
3232+
\end{codeblock}
3233+
\end{example}
3234+
32293235
\pnum
32303236
\begin{note}
32313237
If \tcode{f} and \tcode{g} are both overload sets,

source/templates.tex

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,22 @@
21332133
\end{codeblock}
21342134
\end{example}
21352135

2136+
\pnum
2137+
A non-template function \tcode{F1} is \defn{more partial-ordering-constrained}
2138+
than a non-template function \tcode{F2} if
2139+
\begin{itemize}
2140+
\item
2141+
they have the same non-object-parameter-type-lists\iref{dcl.fct}, and
2142+
\item
2143+
if they are member functions, both are direct members of the same class, and
2144+
\item
2145+
if both are non-static member functions,
2146+
they have the same types for their object parameters, and
2147+
\item
2148+
the declaration of \tcode{F1} is more constrained than
2149+
the declaration of \tcode{F2}.
2150+
\end{itemize}
2151+
21362152
\rSec1[temp.type]{Type equivalence}
21372153

21382154
\pnum
@@ -7866,10 +7882,11 @@
78667882
the parameter is treated as a non-deduced context.
78677883
\item
78687884
If the argument is an overload set (not containing function templates), trial
7869-
argument deduction is attempted using each of the members of the set. If
7870-
deduction succeeds for only one of the overload set members, that member is
7871-
used as the argument value for the deduction. If deduction succeeds for more than
7872-
one member of the overload set the parameter is treated as a non-deduced context.
7885+
argument deduction is attempted using each of the members of the set
7886+
whose associated constraints\iref{temp.constr.constr} are satisfied.
7887+
If all successful deductions yield the same deduced \tcode{A},
7888+
that deduced \tcode{A} is the result of deduction;
7889+
otherwise, the parameter is treated as a non-deduced context.
78737890
\end{itemize}
78747891

78757892
\pnum
@@ -7905,6 +7922,21 @@
79057922
\end{codeblock}
79067923
\end{example}
79077924

7925+
\pnum
7926+
\begin{example}
7927+
\begin{codeblock}
7928+
// All arguments for placeholder type deduction\iref{dcl.type.auto.deduct} yield the same deduced type.
7929+
template<bool B> struct X {
7930+
static void f(short) requires B; // \#1
7931+
static void f(short); // \#2
7932+
};
7933+
void test() {
7934+
auto x = &X<true>::f; // OK, deduces \tcode{void(*)(short)}, selects \#1
7935+
auto y = &X<false>::f; // OK, deduces \tcode{void(*)(short)}, selects \#2
7936+
}
7937+
\end{codeblock}
7938+
\end{example}
7939+
79087940
\rSec3[temp.deduct.funcaddr]{Deducing template arguments taking the address of a function template}
79097941

79107942
\pnum
@@ -8338,16 +8370,22 @@
83388370
deduction is being done.
83398371
\item
83408372
A function parameter for which the associated argument is an
8341-
overload set\iref{over.over}, and one or more of the following apply:
8373+
overload set such that one or more of the following apply:
83428374
\begin{itemize}
83438375
\item
8344-
more than one function matches the function parameter type (resulting in
8345-
an ambiguous deduction), or
8376+
functions whose associated constraints are satisfied and
8377+
that do not all have the same function type
8378+
match the function parameter type (resulting in an ambiguous deduction), or
83468379
\item
8347-
no function matches the function parameter type, or
8380+
no function whose associated constraints are satisfied
8381+
matches the function parameter type, or
83488382
\item
83498383
the overload set supplied as an argument contains one or more function templates.
83508384
\end{itemize}
8385+
\begin{tailnote}
8386+
A particular function from the overload set is selected\iref{over.over}
8387+
after template argument deduction has succeeded\iref{temp.over}.
8388+
\end{tailnote}
83518389
\item A function parameter for which the associated argument is an initializer
83528390
list\iref{dcl.init.list} but the parameter does not have
83538391
a type for which deduction from an initializer list is specified\iref{temp.deduct.call}.

0 commit comments

Comments
 (0)