What is the reason the C++ standard allows(requires) compilers to optimize away calls to copy constructor(in certain cases), even though it might contain observable side effects?
If I’m not mistaken, the "as if" rule already allows compilers to optimize unnecessary code away, as long as the resulting program emulates the observable behavior of the abstract machine defined in the standard.
What were the motives behind making an exception rule? Doesn’t it create inconsistencies in the language?
Is it convenient(or necessary)?
Source: Windows Questions C++