Title
Similar types and reference binding
Status
cd5
Section
9.4.4 [dcl.init.ref]
Submitter
Richard Smith

Created on 2017-07-14.00:00:00 last changed 20 months ago

Messages

Date: 2018-11-15.00:00:00

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

  • T1 is reference-related to T2, or

  • T2 is “noexcept function” and T1 is “function”, where the function types are otherwise the same,

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.

Date: 2018-04-15.00:00:00

Notes from the April, 2018 teleconference:

CWG agreed with the proposed direction.

Date: 2019-02-15.00:00:00

[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.

History
Date User Action Args
2020-12-15 00:00:00adminsetmessages: + msg6396
2020-12-15 00:00:00adminsetstatus: drafting -> cd5
2018-04-11 00:00:00adminsetmessages: + msg6197
2018-04-11 00:00:00adminsetstatus: open -> drafting
2017-07-14 00:00:00admincreate