Created on 2024-10-18.00:00:00 last changed 2 months ago
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
(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
History | |||
---|---|---|---|
Date | User | Action | Args |
2024-10-18 10:47:52 | admin | set | messages: + msg7847 |
2024-10-18 00:00:00 | admin | create |