This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118f. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-11-30
Consider:
struct S {
int i : 5;
};
const int& x = i;
Prior to applying the resolution of issue 2801, this was valid; the reference was bound to a temporary. Now, this is ill-formed.
Suggested resolution:
Change in 9.5.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.5 [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 E of the call to the conversion function, as described for the non-reference copy-initialization, is then used to direct-initialize the reference using the form (E). 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 T1 shall be reference-compatible with cv2 T2; and
- if the reference is an rvalue reference, the initializer expression shall not be an lvalue. [ Note: This can be affected by whether the initializer expression is move-eligible (7.5.5.2 [expr.prim.id.unqual]). -- end note]