This is the mail archive of the gcc-patches@gcc.gnu.org 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, Feb 3, 2010 at 10:36 AM, Michael Matz <matz@suse.de> wrote:
> Hi,
>
> On Wed, 3 Feb 2010, Gabriel Dos Reis wrote:
>
>> > Now, answer this question: "how do I release the storage allocated at
>> > (1)?",
>>
>> ? ?operator delete(p);
>
> Okay. ?It's awkward, but correct. ?I just hope that every user of
> libraries that internally use placement new know that for some returned
> object pointers they must not delete them, but use 'operator delete' to
> just release storage.

A user experienced enough to start using placement new is expected to
be experienced enough to know the distinction between that and a
new-expression.  Consequently, the distinction between a delete-expression
and calling a destructor, or releasing memory.  If not, then, well the user
should not be doing that in the first place.

>
> Another question: The program from last mail again:
>
> struct X { int count; char mem[8]; } *p;
> p = new X;
> ... ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?// e.g. init all members of *p
> float *f = new (&p->mem[0]) float;
> *f = 1.0;
>
> Is it allowed to access p->count after this assignment to float?

If we make the special exception for arrays of characters
(which means 'just storage to hold objects'), then the
access to p->count is OK.

> ?After all it's part of *p, which doesn't exist anymore, hence the access should
> be invalid, right?

Did you mean instead 'hence the access should be VALID'?
If yes, then I agree.  If not, then I don't -- see the remark about
special treatment of arrays of characters.


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