Topic: ANSI draft bug and subsequent compiler bugs ????es


Author: jss@lucid.com (Jerry Schwarz)
Date: 10 Jun 1994 21:00:03 GMT
Raw View
In article <2t6lne$sau@highway.LeidenUniv.nl> rcenteno@iris (Rick Centeno (guest account)) writes:



>   Can anyone tell me whether the following paragraph exerted from the
>   ANSI draft standards of 25 Jan 94 makes sense?
>
>   "In the second alternative, i.e.
>           delete[] Objects;
>   if the dynamic type of the object to be deleted is a class that has a
>   destructor and its static type is different from its dynamic type, the
>   result is undefined."
>
>   I have the distinct feeling that it should read "....a class that has NOT
>   a (VIRTUAL) destructor and its static type....". Otherwise the statement
>   makes no sense to me. However, apparently compiler vendors have read the
>   draft document literally and implemented it to the letter.
>   Consider the following code example:


This isn't something to be implemented its a restriction on the
program. It is saying that if you violate the rule the program will
have undefined behavior.  In other words, your program shouldn't
violate the requirement.  This is a runtime condition (like not
dereferencing null pointers) and so you won't usually get compile time
messages.

The requirement can be stated in the positive fashion as

When you delete an array the (static) type of the pointer must be that
of the actual type of the array objects.  In other words if you do

        delete [] p ;

where  p has type "pointer to T".  Then p must originally have been
allocated with

        new T[...] ;

This constraint is imposed so that the compiler knows how large
the elements of the array are and what destructor to call on them
is.

It is true that the system could be required to stash away this
information (and since RTTI has been added to the language it will be
required to) and use it at the delete, but the current working paper
does not impose that overhead on runtime systems.

I don't know if there is a proposal before the committee to change
this requirement.

  -- Jerry Schwarz(jss@lucid.com)