This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-11-11
According to 11.9.3 [class.base.init] paragraph 11,
A temporary expression bound to a reference member from a brace-or-equal-initializer is ill-formed. [Example:
struct A { A() = default; // OK A(int v) : v(v) { } // OK const int& v = 42; // OK }; A a1; // error: ill-formed binding of temporary to reference A a2(1); // OK, unfortunately—end example]
The rule is intended to apply only if an actual initialization results in such a binding, but it could be read as applying to the declaration of A::v itself. It would be clearer if the restriction were moved into bullet 9.1, e.g.,
if the entity is a non-static data member that has a brace-or-equal-initializer and either
the constructor's class is a union (11.5 [class.union]), and no other variant member of that union is designated by a mem-initializer-id or
the constructor's class is not a union, and, if the entity is a member of an anonymous union, no other member of that union is designated by a mem-initializer-id,
the entity is initialized as specified in 9.4 [dcl.init], and the program is ill-formed if the entity is a reference member and this initialization binds it to a temporary;