Re: [boost] Is there any interest in a library that provides cont ainers with virtual destructors?

----Original Message---- From: Matt Calabrese [mailto:rivorus@gmail.com] Sent: 27 October 2005 06:44 To: boost@lists.boost.org Subject: Re: [boost] Is there any interest in a library that provides containers with virtual destructors?
On 10/27/05, Victor A. Wagner Jr. <vawjr@rudbek.com> wrote:
indeed, but there is no dynamic type vs static type in the example.
If you have a virtual_vector<person>* which points to an instance of people, and you call delete with that pointer as an operand, you have undefined behavior unless virtual_vector<person> has a virtual destructor since virtual_vector<person> is the static type and people is the dynamic type.
Nit: Actually the static type is virtual_vector<person>*, and the dynamic type is people*. (The standard talks about the static and dynamic types of the operand to delete, not the static and dynamic types of the object pointed to by the operand to delete.) (Given the mess I made of the last reference I made to the standard, I shall be interested to see what I have got wrong THIS time!) -- Martin Bonner Martin.Bonner@Pitechnology.com Pi Technology, Milton Hall, Ely Road, Milton, Cambridge, CB4 6WZ, ENGLAND Tel: +44 (0)1223 441434

On 10/27/05, Martin Bonner <martin.bonner@pitechnology.com> wrote:
Nit: Actually the static type is virtual_vector<person>*, and the dynamic type is people*. (The standard talks about the static and dynamic types of the operand to delete, not the static and dynamic types of the object pointed to by the operand to delete.)
I disagree, though admittedly I believe the standard is poor in its wording. If the standard were refering to the static and dynamic type of the pointer, as it does sound since it only states "operand", then the rest of the statement would not make sense since a pointer type is never derived from another pointer type and a pointer never has a virtual destructor. Not only that, but the static and dynamic type of the pointer we are describing would be the same anyway, not different (both its static and dynamic type are virtual_vector<person>*, its target is what has a different static and dynamic type). The wording should probably be changed to say "object to be deleted" instead of "operand", which is how the wording is for deleting a pointer to the first element of a dynamically allocated array. -- -Matt Calabrese

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Matt Calabrese wrote:
[...]
The wording [of 5.3.5/3] should probably be changed to say "object to be deleted" instead of "operand", which is how the wording is for deleting a pointer to the first element of a dynamically allocated array.
There's an open DR for this already: http://www.comeaucomputing.com/iso/cwg_active.html#288 - -- Jim Hyslop Dreampossible: Better software. Simply. http://www.dreampossible.ca Consulting * Mentoring * Training in C/C++ * OOD * SW Development & Practices * Version Management -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDYaOsLdDyDwyJw+MRAhalAJ9B3vtqX59cyV052A8m05ERNWLWYQCfUdlX fBZng1pmco+6Ymf+vbN/JQQ= =Nvuj -----END PGP SIGNATURE-----
participants (3)
-
Jim Hyslop
-
Martin Bonner
-
Matt Calabrese