https://d.puremagic.com/issues/show_bug.cgi?id=12180

           Summary: NRVO with multiple return statements
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: [email protected]
        ReportedBy: [email protected]


--- Comment #0 from Simon <[email protected]> 2014-02-16 03:53:04 
PST ---
In the following code, no return value optimization is performed because foo
contains multiple return statements. But it would be valid to do so, i.e.
bitcopy the appropriate value into the return value of foo without calling the
postblit (and destructor).

In C++, such optimization would be invalid in general. But in D, the struct is
guaranteed not to contain pointers to itself. Therefore structs can be moved
without destructor/postblit.

struct S
{
    this(this) { writefln("copy"); }
}

S foo(bool x)
{
    S a, b;
    if(x) return a;
    else return b;
}

void main() { foo(true); }

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to