How does the compiler determine when it is safe to RVO? And no, I don't mean the rvalue, but the lvalue - if I understand correctly RVO works by "forwarding" the target address to the method, so it returns into the target address instead of the address of a temporary and then copy/assign to the target.
But how does the compiler know it is safe to perform a RVO? What if the lvalue already has some data in it, including dynamically allocated resource? A RVO in such a case may result in a leaked resource. Mayhaps there are some rules which specify whether it is applicable to perform the optimization or stick to using copy or assignment?