Skip to content

Commit 70d1ef1

Browse files
committed
CWG2861 dynamic_cast on bad pointer value
1 parent 005c5e4 commit 70d1ef1

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

source/expressions.tex

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,16 +1034,26 @@
10341034
The pointer value\iref{basic.compound} is unchanged by this conversion.
10351035

10361036
\pnum
1037-
A prvalue of type ``pointer to \cv{} \tcode{D}'', where \tcode{D}
1037+
A prvalue \tcode{v} of type ``pointer to \cv{} \tcode{D}'', where \tcode{D}
10381038
is a complete class type, can be converted to a prvalue of type ``pointer to
10391039
\cv{} \tcode{B}'', where \tcode{B} is a base class\iref{class.derived}
10401040
of \tcode{D}. If \tcode{B} is an
10411041
inaccessible\iref{class.access} or
10421042
ambiguous\iref{class.member.lookup} base class of \tcode{D}, a program
1043-
that necessitates this conversion is ill-formed. The result of the
1044-
conversion is a pointer to the base class subobject of the derived class
1045-
object. The null pointer value is converted to the null pointer value of
1046-
the destination type.
1043+
that necessitates this conversion is ill-formed.
1044+
If \tcode{v} is a null pointer value,
1045+
the result is a null pointer value.
1046+
Otherwise,
1047+
if \tcode{B} is a virtual base class of \tcode{D} and
1048+
\tcode{v} does not point to an object
1049+
whose type is similar\iref{conv.qual} to \tcode{D} and
1050+
that is
1051+
within its lifetime or
1052+
within its period of construction or destruction\iref{class.cdtor},
1053+
the behavior is undefined.
1054+
Otherwise,
1055+
the result is a pointer to the base class subobject of
1056+
the derived class object.
10471057

10481058
\rSec2[conv.mem]{Pointer-to-member conversions}
10491059

@@ -3861,6 +3871,22 @@
38613871
\pnum
38623872
If \tcode{v} is a null pointer value, the result is a null pointer value.
38633873

3874+
\pnum
3875+
If \tcode{v} has type ``pointer to \cv{}~\tcode{U}'' and
3876+
\tcode{v} does not point to an object
3877+
whose type is similar\iref{conv.qual} to \tcode{U} and
3878+
that is
3879+
within its lifetime or
3880+
within its period of construction or destruction\iref{class.cdtor},
3881+
the behavior is undefined.
3882+
If \tcode{v} is a glvalue of type \tcode{U} and
3883+
\tcode{v} does not refer to an object
3884+
whose type is similar to \tcode{U} and
3885+
that is
3886+
within its lifetime or
3887+
within its period of construction or destruction,
3888+
the behavior is undefined.
3889+
38643890
\pnum
38653891
If \tcode{T} is ``pointer to \cv{} \keyword{void}'', then the result
38663892
is a pointer to the most derived object pointed to by \tcode{v}.

0 commit comments

Comments
 (0)