[Bug middle-end/83032] Copy elision for returning subobject

antoshkka at gmail dot com gcc-bugzilla@gcc.gnu.org
Sat Nov 18 15:53:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83032

--- Comment #2 from Antony Polukhin <antoshkka at gmail dot com> ---
> I don't think that's one of the cases where the C++ standard allows elision

Yes, you're right (currently I try to convince C++ standard pepole that
allowing it could be benefical).

But C does not forbit such optimization. Following code could benefit from it:


typedef struct big_ { char data[1024];} big;
struct ts {big a; big b; };
struct ts foo();

big testing1() {
    return foo().b;
}

> So it could only work if the region was at the extremity of the stack and the stack grows in the right direction?

Yes, right. But in the above example it could save you from memcpy.


More information about the Gcc-bugs mailing list