The important bit is that the standard explicitly allows this, and this means that you cannot assume that the side effects of the copy constructor will be fulfilled, since copies can be deleted. The standard requires that the constructor-copy implementation have semantics-constructor-copy semantics, that is, the whole goal is to generate a second object that is semantically equivalent in your domain to the original object. If your program matches this, optimization will not affect the program.
True, on the other hand, this is the only situation in which I can think where the standard allows different visible results from the same program, depending on what the compiler does, but you were told that you should not have side effects in your copy constructor (more precisely, you cannot depend on the exact number of copies made).
As for whether it is worth it, yes it is. In many cases, copies are quite expensive (I intentionally ignore move-constructors in C ++ 11 from the discussion). Consider a function that returns vector<int> if the copy is not deleted, another dynamic distribution is required, a copy of the entire contents of the vector, and then the release of the original memory block, all three operations can be expensive.
In addition, you can force users to modify their code to create an empty object and pass it by reference, but this will make the code more difficult to read.
source share