> It theoretically should be able to do it, but even with -flto, there are likely cases, where it doesn't.
Note that link time optimization only works on a particular binary. What if the function is implemented in a shared library?
> It is less of a problem with C, since you explicitly tell the compiler, whether you want things to get passed as value or pointer.
It works the exact same way in C++, though.
> What if the function is implemented in a shared library
If it is in the public API/ABI of a shared library, than the calling semantics including lifetime and ownership rules are part of the public interface, so of course the compiler can't just change it. You the programmer are responsible for drawing abstraction boundaries and choosing the interface.
> It works the exact same way in C++, though.
Only if write C in C++. The issue here are references, of which the compiler figures out whether this should work like a value or like a pointer. This doesn't exist in C, there the programmer needs to make up its mind and choose. The whole type conversion by making a copy issue also doesn't exist there, because either the type matches or the compiler throws an error.