This is called a copy of Ellision. The compiler is allowed to copy the Hellenes in almost any situation. The most common case is RVO and NRVO, which basically leads to the construction of return values in place. I will demonstrate the transformation.
void g (char* memory) { new (memory) AClass(8); } int main () { char __hidden__variable[sizeof(AClass)]; g(__hidden__variable); AClass& b = *(AClass*)&__hidden__variable[0]; cout -- " after" -- endl;
The code has the same effect, but now there is only one instance of AClass.
source share