Ah, you are right. It theoretically should be able to do it, but even with -flto, there are likely cases, where it doesn't. 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. Also I typically annotate ownership, so it it easy to forget that the compiler doesn't actually knows this. This is a weird limitation, there should be just a parameter attribute to do that.
> 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.