🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2110

Re: Why not op delete(void* v&,size_t);?

#2110
From: Joe Buck
Date: Thu, 05 Oct 1995 07:54
40 lines
2119 bytes
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.

How many programmers would expect that the body of the function

void some_func(const char *);

might be

void some_func(const char * foo) { delete [] foo;}

I would hope that compilers at least emit warnings about this practice,
regardless of what mistake the committee might have made.

-- 
-- Joe Buck 	<jbuck@synopsys.com>	(not speaking for Synopsys, Inc)
Anagrams for "information superhighway":	Enormous hairy pig with fan
						A rough whimper of insanity
---
[ 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: <44uirc$sj9@hermes.synopsys.com>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <9510020800.AA06591@marsh.cacs.usl.edu> <9510031355.2074@mulga.cs.mu.oz.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 05 Oct 95 07:54:51 GMT
Approved: fjh@cs.mu.oz.au
From: jbuck@Synopsys.COM (Joe Buck)
Newsgroups: comp.std.c++
Subject: Re: Why not op delete(void* v&,size_t);?
X-Original-Date: 4 Oct 1995 18:13:00 GMT
Organization: Synopsys Inc., Mountain View, CA 94043-4033
Message-ID: <44uirc$sj9@hermes.synopsys.com>
References: <9510020800.AA06591@marsh.cacs.usl.edu> <9510031355.2074@mulga.cs.mu.oz.au>