Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: delete[]

Thread Tools

Re: delete[]

Andrey Tarasevich
Posts: n/a
VoluMetrix wrote:
> Using vc6 sp5 the following code fails during delete, due to the base
> class having a virtual destructor.
> ...

It is a known defect of the implementation. Your sample code meets just
the requirements that should be met to reproduce the behavior: an
attempt to delete a zero-sized array of polymorphic objects. It is
perfectly legal in C++, but MSVC++ 6 will choke on it at run-time.

A simple investigation will reveal the reason for the crash: the code
attempts to access virtual destructor through the VMT of the first
element in the array, which results in a crash, since there is no first
element in your case. Looks like Microsoft in their MSVC++ 6
implementation decided to support polymorphic deletion of arrays (which
is not a part of C++ standard). It would make a legitimate MS-specific
extension and someone would probably find it useful, but they managed to
screw up along the way and came up with an implementation that produces
a crash in a perfectly standard compliant code.

Best regards,
Andrey Tarasevich
Brainbench C and C++ Programming MVP

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off