https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96004
Bug ID: 96004 Summary: Copy elision with conditional Product: gcc Version: 11.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: antoshkka at gmail dot com Target Milestone: --- Consider the example: struct Struct { Struct() = default; Struct(Struct&&); }; Struct question10(bool b) { if (b) { Struct s{}; return s; } else { return {}; } } It is possible to elide move constructor call as the lifetimes of object `s` and `return {}` do not intersect. (some other compilers already do copy elision in that place https://godbolt.org/z/wdpLkT )