Title
Reference binding with reference-related types
Status
drwp
Section
9.4.4 [dcl.init.ref]
Submitter
Brian Bi

Created on 2023-09-18.00:00:00 last changed 7 months ago

Messages

Date: 2023-10-20.21:07:14

Proposed resolution (approved by CWG 2023-10-20):

Change in 9.4.4 [dcl.init.ref] bullet 5.4 as follows:

  • Otherwise:, T1 shall not be reference-related to T2.
    • If T1 or T2 is a class type and T1 is not reference-related to T2, user-defined conversions are considered using the rules for copy-initialization of an object of type “cv1 T1” by user-defined conversion (9.4 [dcl.init], 12.2.2.5 [over.match.copy], 12.2.2.6 [over.match.conv]); the program is ill-formed if the corresponding non-reference copy-initialization would be ill-formed. The result of the call to the conversion function, as described for the non-reference copy-initialization, is then used to direct-initialize the reference. For this direct-initialization, user-defined conversions are not considered.
    • Otherwise, the initializer expression is implicitly converted to a prvalue of type “T1”. The temporary materialization conversion is applied, considering the type of the prvalue to be “cv1 T1”, and the reference is bound to the result.
    If T1 is reference-related to T2:
    • cv1 shall be the same cv-qualification as, or greater cv-qualification than, cv2; and
    • if the reference is an rvalue reference, the initializer expression shall not be an lvalue. [Note 3: This can be affected by whether the initializer expression is move-eligible (7.5.5.2 [expr.prim.id.unqual]). —end note]
Date: 2023-11-15.00:00:00

[Accepted as a DR at the November, 2023 meeting.]

Consider:

  int* p;
  const int*&& r = static_cast<int*&&>(p);

The intent of core issues 2018 and 2352 was to make this example ill-formed, because it surprisingly introduces a temporary.

History
Date User Action Args
2024-04-05 21:43:46adminsetstatus: dr -> drwp
2023-12-19 10:15:28adminsetstatus: ready -> dr
2023-12-02 15:54:05adminsetstatus: tentatively ready -> ready
2023-10-20 21:07:14adminsetmessages: + msg7471
2023-10-20 21:07:14adminsetstatus: open -> tentatively ready
2023-09-18 00:00:00admincreate