www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12180] New: NRVO with multiple return statements

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: nobody puremagic.com
        ReportedBy: simon.buerger rwth-aachen.de



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: -------
Feb 16 2014