[Issue 19812] Lambda over struct member causes dangling reference to out-of-scope struct

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 4 12:06:37 UTC 2019


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

Suleyman Sahmi (سليمان السهمي) <sahmi.soulaimane at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sahmi.soulaimane at gmail.com

--- Comment #1 from Suleyman Sahmi (سليمان السهمي) <sahmi.soulaimane at gmail.com> ---
Another similar case

```
auto makeI(int m) @safe
{
    static struct S
    {
        int m;
        auto inner()
        {
            class I
            {
                auto get() @safe { return m; }
            }
            return new I;
        }
    }
    scope s = S(m);
    return s.inner();
}

void main() @safe
{
    auto i = makeI(5);

    function()
    {
        // clean stack
        pragma(inline, false);
        long[0x500] a = 0;
    }();

    assert(i.get() == 5);
}
```

https://run.dlang.io/is/xhzYPo

--


More information about the Digitalmars-d-bugs mailing list