This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: segmentation violation due to unnoticed invalid code ?
- To: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Subject: Re: segmentation violation due to unnoticed invalid code ?
- From: Nathan Sidwell <nathan at acm dot org>
- Date: Wed, 14 Apr 1999 15:41:16 +0100
- CC: Luc Maisonobe <Luc dot Maisonobe at cnes dot fr>, egcs-bugs at egcs dot cygnus dot com, Martine dot Julien at cisi dot cnes dot fr
- Organization: University of Bristol
- References: <199904130754.HAA23135@lurien.cst.cnes.fr> <orvhf0rz8s.fsf@dcc.unicamp.br>
- Reply-To: nathan at compsci dot bristol dot ac dot uk
Alexandre Oliva wrote:
>
> On Apr 13, 1999, Luc.Maisonobe@cnes.fr (Luc Maisonobe) wrote:
>
> > A *a = new A [1];
> > delete [] ((void *) a);
>
> When you new an array, you must delete[] it using a pointer of the
> actual type of the array elements. Since A is not void, the behavior
> is undefined.
> > Of course this is weird code (it has been corrected since then), but I
> > would suggest egcs should complain about freeing an anonymous pointer.
>
> Yep, it would probably be a nice feature, since `delete[] (void*)foo'
> can *never* be well-defined behavior, as `new void[n]' is ill-formed.
I believe both `delete (void *)e' and `delete[] (void *)e' to be undefined. The
former is because the static type (void) must be different to the dynamic type
of the object (fails first part of 5.3.5/3) The latter is also undefined
because of the second part of 5.3.5/3 as footnote 73 notes.
So, we could warn on both instances. I guess there might be some code using
`delete e' to deallocate random blobs of memory, but shouldn't they use
`operator delete(e)' instead?
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
You can up the bandwidth, but you can't up the speed of light
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk