https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123418

            Bug ID: 123418
           Summary: d: RVO/NRVO not done when function has an out contract
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: d
          Assignee: ibuclaw at gdcproject dot org
          Reporter: ibuclaw at gcc dot gnu.org
  Target Milestone: ---

Compiled with -fno-postconditions and the result gets returned via RVO.

Compiled with -fpostconditions and (N)RVO is not done.  The result is instead
copied to a temporary "__result" variable.

The generated result variable of functions - if one exists - should have its
DECL_EXPR_VALUE pointing at the DECL_RESULT decl.

```
struct S67
{
    S67* ptr;

    this(int)
    {
        pragma(inline, false);
        ptr = &this;
    }

    @disable this(this);
}

pragma(inline, false)
S67 make67()
{
    return S67(1);
}

S67 f67()
out (s; s.ptr == &s)  // fails here
{
    return make67();
}

void main()
{
    S67 s = f67();
    assert(s.ptr == &s);
}
```

Reply via email to