Title
Confusing specification for dynamic_cast
Status
cd5
Section
7.6.1.7 [expr.dynamic.cast]
Submitter
Shiyao Ma

Created on 2017-02-08.00:00:00 last changed 39 months ago

Messages

Date: 2018-11-15.00:00:00

Proposed resolution (November, 2018):

Change 7.6.1.7 [expr.dynamic.cast] paragraphs 4-6 as follows:

If the value of v is a null pointer value in the pointer case, the result is the null pointer value of type T.

If T is “pointer to cv1 B” and v has type “pointer to cv2 D” such that B is a base class of D, the result is a pointer to the unique B subobject of the D object pointed to by v, or a null pointer value if v is a null pointer value. Similarly, if T is...

Otherwise, v shall be a pointer to or a glvalue of a polymorphic type (11.7.3 [class.virtual]).

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

Date: 2019-02-15.00:00:00

[Accepted as a DR at the February, 2019 meeting.]

From editorial issue 1453.

According to 7.6.1.7 [expr.dynamic.cast] paragraph 4,

If the value of v is a null pointer value in the pointer case, the result is the null pointer value of type T.

Paragraph 5 deals with the case of a simple up-cast, where no runtime type identification is required. Paragraph 6 says,

Otherwise, v shall be a pointer to or a glvalue of a polymorphic type (11.7.3 [class.virtual]).

This organization of the material makes it sound as if the requirement for polymorphic class types does not apply if the argument is a null pointer value, which, of course, cannot be determined at compile time. The intent is that a null pointer value argument produces a null pointer value result, regardless of whether the relationship between the classes requires runtime type identification or not, but that the requirement for polymorphic classes applies for all casts that are not simple up-casts. The wording should be clarified.

History
Date User Action Args
2020-12-15 00:00:00adminsetmessages: + msg6379
2020-12-15 00:00:00adminsetstatus: open -> cd5
2017-02-08 00:00:00admincreate