Skip to content

Commit 8fb9318

Browse files
burblebeetkoeppe
authored andcommitted
CWG2803 Overload resolution for reference binding of similar types
[over.ics.ref]p1 Use "can" instead of "may" inside note.
1 parent 03f6db1 commit 8fb9318

File tree

1 file changed

+51
-16
lines changed

1 file changed

+51
-16
lines changed

source/overloading.tex

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,11 +2317,32 @@
23172317
\rSec4[over.ics.ref]{Reference binding}
23182318

23192319
\pnum
2320-
When a parameter of reference type binds directly\iref{dcl.init.ref} to an
2321-
argument expression, the implicit conversion sequence is the identity conversion,
2322-
unless the argument expression has a type that is a derived class of the parameter
2323-
type, in which case the implicit conversion sequence is a derived-to-base
2320+
When a parameter of type ``reference to \cv \tcode{T}''
2321+
binds directly\iref{dcl.init.ref} to an argument expression:
2322+
\begin{itemize}
2323+
\item
2324+
If the argument expression has a type that
2325+
is a derived class of the parameter type,
2326+
the implicit conversion sequence is a derived-to-base
23242327
conversion\iref{over.best.ics}.
2328+
2329+
\item
2330+
Otherwise,
2331+
if \tcode{T} is a function type, or
2332+
if the type of the argument is possibly cv-qualified \tcode{T}, or
2333+
if \tcode{T} is an array type of unknown bound with element type \tcode{U} and
2334+
the argument has an array type of known bound whose
2335+
element type is possibly cv-qualified \tcode{U},
2336+
the implicit conversion sequence is the identity conversion.
2337+
\begin{note}
2338+
When \tcode{T} is a function type,
2339+
the type of the argument can differ only by the presence of \keyword{noexcept}.
2340+
\end{note}
2341+
2342+
\item
2343+
Otherwise, the implicit conversion sequence is a qualification conversion.
2344+
\end{itemize}
2345+
23252346
\begin{example}
23262347
\begin{codeblock}
23272348
struct A {};
@@ -2334,9 +2355,8 @@
23342355
If the parameter binds directly to the result of
23352356
applying a conversion function to the argument expression, the implicit
23362357
conversion sequence is a user-defined conversion sequence\iref{over.ics.user}
2337-
whose second standard conversion sequence is either an identity conversion or,
2338-
if the conversion function returns an entity of a type that is a derived class
2339-
of the parameter type, a derived-to-base conversion.
2358+
whose second standard conversion sequence is
2359+
determined by the above rules.
23402360

23412361
\pnum
23422362
When a parameter of reference type is not bound directly to an argument
@@ -2767,28 +2787,32 @@
27672787
\item
27682788
\tcode{S1} and \tcode{S2} differ only
27692789
in their qualification conversion\iref{conv.qual} and
2770-
yield similar types \tcode{T1} and \tcode{T2}, respectively,
2771-
where \tcode{T1} can be converted to \tcode{T2} by a qualification conversion.
2790+
yield similar types \tcode{T1} and \tcode{T2}, respectively
2791+
(where a standard conversion sequence that is a reference binding
2792+
is considered to yield the cv-unqualified referenced type),
2793+
where \tcode{T1} and \tcode{T2} are not the same type, and
2794+
\tcode{const T2} is reference-compatible with \tcode{T1}\iref{dcl.init.ref}.
27722795
\begin{example}
27732796
\begin{codeblock}
27742797
int f(const volatile int *);
27752798
int f(const int *);
27762799
int i;
27772800
int j = f(&i); // calls \tcode{f(const int*)}
2801+
int g(const int*);
2802+
int g(const volatile int* const&);
2803+
int* p;
2804+
int k = g(p); // calls \tcode{g(const int*)}
27782805
\end{codeblock}
27792806
\end{example}
27802807
or, if not that,
27812808
\item
27822809
\tcode{S1}
27832810
and
27842811
\tcode{S2}
2785-
include reference bindings\iref{dcl.init.ref}, and the types to which the references
2786-
refer are the same type except for top-level cv-qualifiers, and the type to
2787-
which the reference initialized by
2788-
\tcode{S2}
2789-
refers is more cv-qualified than the type to which the reference initialized by
2790-
\tcode{S1}
2791-
refers.
2812+
bind ``reference to \tcode{T1}'' and ``reference to \tcode{T2}'',
2813+
respectively\iref{dcl.init.ref},
2814+
where \tcode{T1} and \tcode{T2} are not the same type, and
2815+
\tcode{T2} is reference-compatible with \tcode{T1}.
27922816
\begin{example}
27932817
\begin{codeblock}
27942818
int f(const int &);
@@ -2808,6 +2832,17 @@
28082832
a.f(); // calls \tcode{X::f() const}
28092833
b.f(); // calls \tcode{X::f()}
28102834
}
2835+
2836+
int h1(int (&)[]);
2837+
int h1(int (&)[1]);
2838+
int h2(void (&)());
2839+
int h2(void (&)() noexcept);
2840+
void g2() {
2841+
int a[1];
2842+
h1(a); // calls \tcode{h1(int (\&)[1])}
2843+
extern void f2() noexcept;
2844+
h2(f2); // calls \tcode{h2(void (\&)() noexcept)}
2845+
}
28112846
\end{codeblock}
28122847
\end{example}
28132848
\end{itemize}

0 commit comments

Comments
 (0)