Full name of submitter (unless configured in github; will be published with the issue): Hubert Tong
Reference (section label): [class.temporary]
Link to reflector thread (if any): N/A
Issue description:
CWG 2894 will clarify that RefType{} produces a glvalue (instead of a prvalue). Once that happens, [class.temporary] will require an update to allow lifetime-extension of any temporary bound to the reference initialized by the function-style cast expression. In particular, the function-style cast is not mapped to static_cast, etc. in this case and the temporary materialization occurs within the initialization for the reference formed by the cast itself.
Implementations appear to agree already that such lifetime-extension occurs (https://godbolt.org/z/EWczhzaf6):
int glob;
struct A {
constexpr ~A() { p = &glob; }
int *p;
};
constexpr int f() {
typedef const A &AR;
const A &ref = AR{0};
delete ref.p;
return 0;
}
extern constexpr int x = f(); // okay
Suggested resolution:
Add a bullet to [class.temporary]/6:
Full name of submitter (unless configured in github; will be published with the issue): Hubert Tong
Reference (section label): [class.temporary]
Link to reflector thread (if any): N/A
Issue description:
CWG 2894 will clarify that
RefType{}produces a glvalue (instead of a prvalue). Once that happens, [class.temporary] will require an update to allow lifetime-extension of any temporary bound to the reference initialized by the function-style cast expression. In particular, the function-style cast is not mapped tostatic_cast, etc. in this case and the temporary materialization occurs within the initialization for the reference formed by the cast itself.Implementations appear to agree already that such lifetime-extension occurs (https://godbolt.org/z/EWczhzaf6):
Suggested resolution:
Add a bullet to [class.temporary]/6:
a
[ ... ]
a function-style cast to a reference type where the reference is