[C++ PATCH] Fix placement new if operator new has 2nd argument REFERENCE_TYPE (PR c++/34862)

Gabriel Dos Reis gdr@integrable-solutions.net
Wed Feb 6 22:41:00 GMT 2008


On Feb 5, 2008 2:01 PM, Mark Mitchell <mark@codesourcery.com> wrote:
>
> Richard Guenther wrote:
> > On Feb 5, 2008 7:06 PM, Jason Merrill <jason@redhat.com> wrote:
> >> Richard Guenther wrote:
> >>> The problem arises at the point of inlining, where the optimizers need to see
> >>> that at the _beginning_ of the inlined new operator the dynamic type
> >>> of the storage is changing.
> >> Why?  The new operator isn't doing anything to the storage.
> >
> > In PR33407 an implementation of ::new (called by new expression) might
> > choose to zero-initialize storage for example.  But you are probably right,
> > as the new type is in effect only at the point the new object is constructed
> > which happens by a constructor called on the result pointer.
>
> I agree; until operator new returns, it's got to be the case that the
> storage still has whatever type it had before you called new.  That can
> be reasonably required by the implementation of the operator.
>
> For example, if the storage is chained onto a free list when not in use,
> then the operator might need to remove it from the free list.
>
> void *operator new(size_t bytes, node *node) {
>     // Remove node from the list.
>     node->prev->next = node->next;
>     return node;
> }
>
> So, I think the point of magic type change occurs upon return from the
> operator new function, right before you call the constructor for the new
> object.

Indeed; that reflects the idea that an object's lifetime starts after
constructor
finishes its job.



More information about the Gcc-patches mailing list