Reference: Copy Elision
只有在被宣布为初始目标时,该目标才可以适用:
struct C { /* ... */ };
C f();
struct D;
D g();
struct D : C
{
D() : C(f()) {} // no elision when initializing a base-class subobject
D(int) : D(g()) {} // no elision because the D object being initialized might
// be a base-class subobject of some other class
};
If the compiler can make out the memory layout of a non-overlapping object (such as of a primary data type) to elide copy and instead construct the object at its destination, why can t it do the same for overlapping objects as well? What is the limitation at the system level that would make it not possible for the compiler to do such copy elision?