http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57176



             Bug #: 57176

           Summary: copy elision with function arguments passed by value

    Classification: Unclassified

           Product: gcc

           Version: 4.9.0

            Status: UNCONFIRMED

          Keywords: missed-optimization

          Severity: enhancement

          Priority: P3

         Component: c++

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: gli...@gcc.gnu.org





Hello,



it is a well know issue that copy elision is allowed but never implemented in

cases like:



A f(A x){

  return x;

}



and the reason is that the caller and the callee have to communicate for it to

happen. In C, the function would be:

void f_impl(A* ret_p, A* x_p);

with the caller being responsible for allocating space for ret and x and making

the copy into x.



It seems that to make it work, we would need to notice that f is eligible for

this optimization, mark it somehow (indicating which argument can be used as

return value) and clone it:

void f_impl_nrvo(A* ret_x_p);



Callers who would see this mark would instead call the clone with one less

argument.



There are clearly many parts of the front-end I don't understand enough to do

this, but does it look like a correct and workable approach?

Reply via email to