Movatterモバイル変換


[0]ホーム

URL:


This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 119a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-12-20


2861.dynamic_cast on bad pointer value

Section:7.6.1.7  [expr.dynamic.cast]    Status:CD7    Submitter:Jim X    Date:2024-02-06

[Accepted as a DR at the June, 2024 meeting.]

(From submission#497.)

Base-to-derived casts and cross-casts need to inspect the vtable ofa polymorphic type. However, this is not defined as an "access" andthere is no provision for undefined behavior analoguous to7.2.1 [basic.lval] paragraph 11.

Proposed resolution (approved by CWG 2024-06-26):

  1. Add a new paragraph after 7.6.1.7 [expr.dynamic.cast] paragraph 6 asfollows:

    If v is a null pointer value, the result is a null pointer value.

    Ifv has type "pointer tocvU"andv does not point to an object whose type is similar(7.3.6 [conv.qual]) toU and that is within itslifetime or within its period of construction or destruction(11.9.5 [class.cdtor]), the behavior is undefined.Ifv is a glvalue of typeU andv does notrefer to an object whose type is similar toU and that iswithin its lifetime or within its period of construction ordestruction, the behavior is undefined.

  2. Change in 7.3.12 [conv.ptr] paragraph 3 as follows:

    A prvaluev of type “pointer to cv D”,where D is a complete class type, can be converted to a prvalue oftype “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 isill-formed.The result of the conversion is a pointer to the baseclass subobject of the derived class object. The null pointer value isconverted to the null pointer value of the destination type.Ifv is a null pointer value, the result is a nullpointer value. Otherwise, ifB is a virtual base classofD andv does not point to an object whose type issimilar (7.3.6 [conv.qual]) toD and that is withinits 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 derivedclass object.



[8]ページ先頭

©2009-2026 Movatter.jp