[Issue 12180] New: NRVO with multiple return statements

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Feb 16 03:53:08 PST 2014


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


--- Comment #0 from Simon <simon.buerger at rwth-aachen.de> 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: -------


More information about the Digitalmars-d-bugs mailing list