TITLE: delete through a const pointer (comp.lang.c++.moderated) E: ezust@magmacom.com (Acme Instant Dehydrated Boulder Kit) >deleting a pointer to a constant object is, IMHO, something which should not >be allowed by the language. FJH: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson), 6 Apr 96 You're in good company - Bjarne Stroupstrup thought the same thing, at least originally. However, this was always a little bit inconsistent, since C++ has always permitted destroying an object via a pointer to const by explicitly invoking the destructor, as in `p->~Foo()'. When the committee decided to allow `const Foo *p = new const Foo', it became pretty clear that they also had to allow `delete p'. So since November 94, C++ has allowed deleting a pointer to a constant object. E: >And it is also something which is not permitted >by some compilers. FJH: Yes, not all compilers have caught up with that Nov 94 decision. E: >I checked the draft standard myself and found this: In the section >5.3.5 it says this: > >4 It is unspecified whether the deletion of an object changes its value. > >If I interpret this the way I think I should, what this means is that in >theory it is okay to delete a pointer to constant memory, but compilers >can conform to the standard by generating an error, warning, or just >compiling it without any warning or error. Am I right? FJH: No. I think that text was intended to allow implementations to set pointers to deleted objects to bogus values, so that any use of those pointers would be quickly trapped. In any case, the wording has been improved in the latest draft, and those words no longer appear. E: >Why doesn't something get added to the draft standard which emphatically >states whether this should be permitted or not? It seems rather silly to >leave this unspecified... The April 96 draft contains the following text (5.3.5[expr.delete]/2): "[Note: a pointer to a const type can be the subject of a delete-expression.]".