This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-12-19
(From submission #625.)
Issue 2894 will clarify that a function-style cast to reference type produces a glvalue, not a prvalue. However, 6.7.7 [class.temporary] does not specify lifetime-extension for this case, even though implementations uniformly do extend the lifetime.
For example:
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:
Change in 6.7.7 [class.temporary] paragraph 6 as follows:
- a
- const_cast (7.6.1.11 [expr.const.cast]),
- ...
- an explicit type conversion (functional notation) (7.6.1.4 [expr.type.conv]) to a reference type whose initializer is a braced-init-list where the reference is
- bound directly to the glvalue result of one of these expressions that is the sole element of the braced-init-list or
- bound to the result of a temporary materialization conversion,
- a conditional expression (7.6.16 [expr.cond]) that is a glvalue where the second or third operand is one of these expressions, or