www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20401] New: ref variable copied before return

https://issues.dlang.org/show_bug.cgi?id=20401

          Issue ID: 20401
           Summary: ref variable copied before return
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: sahmi.soulaimane gmail.com

Test case:

```
void main()
{
    int i;
    assert(&passthrough(i) == &i);
}

ref int passthrough(return ref int i)
{
    return get().flag ? i : i;
}

S get() { return S(); }

struct S
{
    bool flag;
    ~this(){}
}
```

Assertion fails. `passthrough` should return `i` without making a copy of it.

--
Nov 16 2019