Topic: Ordering of operators new and constructors?
Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Sat, 11 Jun 1994 19:29:45 GMT Raw View
chatty@cenatls.cena.dgac.fr (Stephane Chatty) writes:
>Until now, I assumed that operator new was called right before
>the constructor, so that:
>
>new B (new A)
>
>resulted in the following sequence:
>
>A::new, A::A, B::new, B::B
>
>but I just discovered that g++ has a different behaviour:
>
>B::new, A::new, A::A, B::B
>
>Is this legal?
Yes, this is legal.
>Is anything said in the standard about this?
No, since there's no standard yet.
The latest draft of the working paper says the following:
Whether the allocation function is called before evaluating the
constructor arguments, after evaluating the constructor arguments but
before entering the constructor, or by the constructor itself is
unspecified. It is also unspecified whether the arguments to a
constructor are evaluated if the allocation function returns the null
pointer or throws an exception.
--
Fergus Henderson - fjh@munta.cs.mu.oz.au
Author: chatty@cenatls.cena.dgac.fr (Stephane Chatty)
Date: Thu, 2 Jun 1994 09:42:40 GMT Raw View
I could not find anything precise in the ARM about
the time when operator new is called. I understand that
it can be called by the constructor or before the constructor.
But in the latter case, nothing is said about when it can happen.
Until now, I assumed that operator new was called right before
the constructor, so that:
new B (new A)
resulted in the following sequence:
A::new
A::A
B::new
B::B
but I just discovered that g++ has a different behaviour:
B::new
A::new
A::A
B::B
Is this legal? Is anything said in the standard about this?
Author: jason@cygnus.com (Jason Merrill)
Date: Thu, 2 Jun 1994 20:22:20 GMT Raw View
>>>>> Stephane Chatty <chatty@cenatls.cena.dgac.fr> writes:
> Is this legal?
Yes.
> Is anything said in the standard about this?
Yes:
10Whether the allocation function is called before evaluating the
constructor arguments, after evaluating the constructor arguments but
before entering the constructor, or by the constructor itself is
unspecified. It is also unspecified whether the arguments to a
constructor are evaluated if the allocation function returns the null
pointer or throws an exception.
Jason