The compiler can also optimize away functions returning copies of variables, if they are not too complicated.
But you cannot return a reference to a local variable!