This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 110b. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2023-01-15


2352. Similar types and reference binding

Section: 9.4.4  [dcl.init.ref]     Status: CD5     Submitter: Richard Smith     Date: 2017-07-14

[Accepted as a DR at the February, 2019 meeting.]

In an example like

  int *ptr;
  const int *const &f() {
    return ptr;
  }

What is returned is a reference to a temporary instead of binding directly to ptr. The rules for reference-related types should say that T is reference-related to U if U* can be converted to T* by a qualification conversion.

Notes from the April, 2018 teleconference:

CWG agreed with the proposed direction.

Proposed resolution (November, 2018):

Change 9.4.4 [dcl.init.ref] paragraph 4 as follows:

Given types “cv1 T1” and “cv2 T2”, “cv1 T1” is reference-related to “cv2 T2” if T1 is the same type as similar (7.3.6 [conv.qual]) to T2, or T1 is a base class of T2. “cv1 T1” is reference-compatible with “cv2 T2” if

and cv1 is the same cv-qualification as, or greater cv-qualification than, cv2 a prvalue of type “pointer to cv2 T2” can be converted to the type “pointer to cv1 T1” via a standard conversion sequence (7.3 [conv]). In all cases where the reference-related or reference-compatible relationship of two types is used to establish the validity of a reference binding, and T1 is a base class of T2 and the standard conversion sequence would be ill-formed, a program that necessitates such a binding is ill-formed if T1 is an inaccessible (11.8 [class.access]) or ambiguous (6.5.2 [class.member.lookup]) base class of T2.