|
2317 | 2317 | \rSec4[over.ics.ref]{Reference binding}
|
2318 | 2318 |
|
2319 | 2319 | \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 |
2324 | 2327 | 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 | + |
2325 | 2346 | \begin{example}
|
2326 | 2347 | \begin{codeblock}
|
2327 | 2348 | struct A {};
|
|
2334 | 2355 | If the parameter binds directly to the result of
|
2335 | 2356 | applying a conversion function to the argument expression, the implicit
|
2336 | 2357 | 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. |
2340 | 2360 |
|
2341 | 2361 | \pnum
|
2342 | 2362 | When a parameter of reference type is not bound directly to an argument
|
|
2767 | 2787 | \item
|
2768 | 2788 | \tcode{S1} and \tcode{S2} differ only
|
2769 | 2789 | 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}. |
2772 | 2795 | \begin{example}
|
2773 | 2796 | \begin{codeblock}
|
2774 | 2797 | int f(const volatile int *);
|
2775 | 2798 | int f(const int *);
|
2776 | 2799 | int i;
|
2777 | 2800 | 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*)} |
2778 | 2805 | \end{codeblock}
|
2779 | 2806 | \end{example}
|
2780 | 2807 | or, if not that,
|
2781 | 2808 | \item
|
2782 | 2809 | \tcode{S1}
|
2783 | 2810 | and
|
2784 | 2811 | \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}. |
2792 | 2816 | \begin{example}
|
2793 | 2817 | \begin{codeblock}
|
2794 | 2818 | int f(const int &);
|
|
2808 | 2832 | a.f(); // calls \tcode{X::f() const}
|
2809 | 2833 | b.f(); // calls \tcode{X::f()}
|
2810 | 2834 | }
|
| 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 | +} |
2811 | 2846 | \end{codeblock}
|
2812 | 2847 | \end{example}
|
2813 | 2848 | \end{itemize}
|
|
0 commit comments