Bug 96004 - Copy elision with conditional
Summary: Copy elision with conditional
Status: RESOLVED DUPLICATE of bug 58487
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks: RVO
  Show dependency treegraph
 
Reported: 2020-06-30 14:24 UTC by Antony Polukhin
Modified: 2023-06-06 16:11 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-10-31 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Antony Polukhin 2020-06-30 14:24:49 UTC
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 )
Comment 1 Óscar Fuentes 2021-11-19 20:42:14 UTC
This looks like a duplicate of PR53637 / PR53637.
Comment 2 Andrew Pinski 2022-10-31 18:09:35 UTC
Confirmed.
Comment 3 Jason Merrill 2023-06-06 16:11:54 UTC
(In reply to Óscar Fuentes from comment #1)
> This looks like a duplicate of PR53637 / PR53637.

More 58487.

*** This bug has been marked as a duplicate of bug 58487 ***