This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix C++ strict-aliasing issues with memcpy folding


On Wed, 3 Feb 2010, Gabriel Dos Reis wrote:

> See 3.8/3.

Right.  That's what I'm saying; you aren't allowed to call delete on 
non-existing objects.  That's all fine and well.

> > Now, if you say (as you did upthread) that object *p ceased to exist with
> > the placement new, then p doesn't point to an object anymore, hence
> > 'delete p' is undefined.
> Yes, but I still do not see what the real problem is.
> Would you mind clarifying?

I'll try: You were saying that my playing with placement new on parts of 
*p, destroys *p.  The standard then disallows delete p.  Further in this 
thread it was argued that placement new is supposed to only change types 
of anonymous storage, not static or autmatic storage.  I'm trying to 
connect those statements to derive something that might surprise people, 
and IMO makes placement new to reuse storage even more dubious.  The way I 
derive this goes like so:

struct X { int count; char mem[8]; } *p;
p = new X;                           // allocates storage (1)
...                                  // e.g. init all members of *p
float *f = new (&p->mem[0]) float;   // now *p is no object anymore
*f = 1.0;

Now, answer this question: "how do I release the storage allocated at 
(1)?", I can't use 'delete p', but I also can't use 'f' for deallocation 
as it's pointing into the middle of some allocated storage.  I don't have 
any other pointers I might try to use.  I can't use free (p), because I 
don't know if the new at (1) actually used malloc or something else.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]