Topic: Defect Report: Misuse of "static type" with respect to pointers.


Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: 19 May 01 11:39:59 GMT
Raw View
 [Moderator's note: this defect report has been
 forwarded to the C++ committee. -moderator(fjh).]

For delete expressions, 5.3.5 [expr.delete] paragraph 1 says ".. The
operand shall have a pointer type, or a class type having a single
conversion function to a pointer type. ..."
However, paragraph 3 of that same section says: ""... if the static type
of the operand is different from its dynamic type, the static type shall
be a base class of the operand's dynamic type and the static type shall
have a virtual destructor or the behavior is undefined."

Since the operand must be of pointer type, its static type is
necessarily the same as its dynamic type. That clause is clearly
referring to the object being pointed at, and not to the pointer operand
itself.

Correcting the wording gets a little complicated, because dynamic and
static types are attributes of expressions, not objects, and there's no
sub-expression of a _delete-expression_ which has the relevant types.

Suggested correction:
" ... then there is a static type and a dynamic type that the
hypothetical expression
'(* _const-expression_)' would have. If that static type is different
from that dynamic type, then that static type shall be a base class of
that dynamic type, and that static type shall have a virtual destructor,
or the behavior is undefined."

There's precedent for such use of hypothetical constructs: see 5.10
[expr.eq] paragraph 2, and 8.1 [dcl.name] paragraph 1.

Section 10.3 [class.virtual] paragraph 3 has a similar problem. It
refers to "... the type of the pointer or reference denoting the object
(the static type)". The type of the pointer is different from the type
of the reference, both of which are different from the static type of
'*pointer', which is what I think was actually intended. Paragraph 6
contains the exact same wording, in need of the same correction. In this
case, perhaps replacing "pointer or reference" with "expression" would
be the best fix. In order for this fix to be sufficient,
'pointer->member' must be considered equivalent to '(*pointer).member',
in which case the "expression" referred to would be '(*pointer)'.

Section 12.5 [class.free] paragraph 4 says that "... if a
_delete-expression_ is used to deallocate a class object whose static
type has ...". This should be changed to "... if a _delete-expression_
is used to deallocate a class object through a pointer expression whose
dereferenced static type would have ...". The same problem occurs later,
when it says that the "static and dynamic types of the object shall be
identical". In this case you could replace "object" with "dereferenced
pointer expression".

Footnote 104 says that " ... 5.3.5 requires that ... the static type of
the _delete-expression_'s operand be the same as its dynamic type." This
would need to be changed to  "... the _delete-expression_'s dereferenced
operand ...".
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]