Created on 2024-02-06.00:00:00 last changed 4 months ago
Proposed resolution (approved by CWG 2024-06-26):
Add a new paragraph after 7.6.1.7 [expr.dynamic.cast] paragraph 6 as follows:
If v is a null pointer value, the result is a null pointer value.
If v has type "pointer to cv U" and v does not point to an object whose type is similar (7.3.6 [conv.qual]) to U and that is within its lifetime or within its period of construction or destruction (11.9.5 [class.cdtor]), the behavior is undefined. If v is a glvalue of type U and v does not refer to an object whose type is similar to U and that is within its lifetime or within its period of construction or destruction, the behavior is undefined.
Change in 7.3.12 [conv.ptr] paragraph 3 as follows:
A prvalue v of type “pointer to cv D”, where D is a complete class type, can be converted to a prvalue of type “pointer to cv B”, where B is a base class (11.7 [class.derived]) of D. If B is an inaccessible (11.8 [class.access]) or ambiguous (6.5.2 [class.member.lookup]) base class of D, a program that necessitates this conversion is ill-formed.The result of the conversion is a pointer to the base class subobject of the derived class object. The null pointer value is converted to the null pointer value of the destination type.If v is a null pointer value, the result is a null pointer value. Otherwise, if B is a virtual base class of D and v does not point to an object whose type is similar (7.3.6 [conv.qual]) to D and that is within its lifetime or within its period of construction or destruction (11.9.5 [class.cdtor]), the behavior is undefined. Otherwise, the result is a pointer to the base class subobject of the derived class object.
[Accepted as a DR at the June, 2024 meeting.]
(From submission #497.)
Base-to-derived casts and cross-casts need to inspect the vtable of a polymorphic type. However, this is not defined as an "access" and there is no provision for undefined behavior analoguous to 7.2.1 [basic.lval] paragraph 11.
History | |||
---|---|---|---|
Date | User | Action | Args |
2024-07-20 13:52:34 | admin | set | status: ready -> dr |
2024-06-26 19:14:41 | admin | set | status: tentatively ready -> ready |
2024-04-19 21:17:21 | admin | set | status: review -> tentatively ready |
2024-04-05 21:08:10 | admin | set | messages: + msg7655 |
2024-04-05 21:08:10 | admin | set | status: open -> review |
2024-02-06 00:00:00 | admin | create |