Article View: comp.std.c++
Article #2120Re: Why not op delete(void* v&,size_t);?
From: Fergus Henderson
Date: Thu, 05 Oct 1995 14:56
Date: Thu, 05 Oct 1995 14:56
43 lines
2520 bytes
2520 bytes
jbuck@Synopsys.COM (Joe Buck) writes:
>fjh@munta.cs.mu.OZ.AU (Fergus Henderson) writes:
>>However, consider a closely related example:
>>
>> const X* xp = new X;
>> // ...
>> delete xp;
>>
>>According to the ARM, this code was illegal - it was an error to delete
>>a pointer to const. However, the ARM never spelt out whether or not
>>`new const X' was legal. At the November 94 meeting in Valley Forge,
>>Pa., the C++ committee decided to allow `new const X'; having decided
>>to allow this, it was pretty much a requirement to allow deletion of a
>>pointer to const, otherwise there would be no convenient way to delete
>>objects allocated with `new const X'. So that example is also legal,
>>although some compilers may not yet allow it.
>
>IMHO, this decision was a serious mistake, as before the decision, a
>program that did not cast away const could not alter an object that it
>only had a const pointer or reference to; now it can. It can hardly
>be argued that deleting an object does not modify it.
That's not correct. Even before the decision at Valley Forge, it
was legal for a function to destroy a const object. For example,
following code was always allowed (well, at least since Cfront 2.x):
void foo(const T *p) {
p->~T();
}
So the guarantee that you are arguing should have been preserved
never existed in the first place.
--
Fergus Henderson | "Australia is the richest country in the world,
fjh@cs.mu.oz.au | according to a new system of measuring wealth
http://www.cs.mu.oz.au/~fjh | announced by the World Bank yesterday."
PGP: finger fjh@128.250.37.3 | - Melbourne newspaper "The Age", 18 Sept 1995.
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<9527818.9585@mulga.cs.mu.OZ.AU>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamageReferences:
<9510020800.AA06591@marsh.cacs.usl.edu> <9510031355.2074@mulga.cs.mu.oz.au> <44uirc$sj9@hermes.synopsys.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson) Newsgroups: comp.std.c++ Subject: Re: Why not op delete(void* v&,size_t);? Date: 5 Oct 1995 14:56:09 GMT Organization: Computer Science, University of Melbourne, Australia Sender: news@cs.mu.OZ.AU (CS-Usenet) Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <9527818.9585@mulga.cs.mu.OZ.AU> References: <9510020800.AA06591@marsh.cacs.usl.edu> <9510031355.2074@mulga.cs.mu.oz.au> <44uirc$sj9@hermes.synopsys.com> NNTP-Posting-Host: taumet.eng.sun.com Originator: clamage@taumet