Does the following statement invoke undefined behavior?
The example uses built-in types but of course what I really care about are user-defined types.
This is a question about evaluation rules... I believe it is well behaved because the rhs argument to operator= must be fully evaluated before the assignment occurs. But does the copy constructor complete before new returns?
int
main(void)
{
int * p1 = new int(3);
// is this legal? (ignore the memory leak)
p1 = new int(*p1); // clone
return 0;
}
The views expressed are those of the author and do not reflect any position taken by the Goverment of the United States of America, National Aeronautics and Space Administration (NASA), Jet Propulsion Laboratory (JPL), or California Institute of Technology (CalTech)