[Issue 19111] Returning a reference to local array results in garbage

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 26 09:50:50 UTC 2018


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

anonymous4 <dfj1esp02 at sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID
                 OS|Linux                       |All

--- Comment #2 from anonymous4 <dfj1esp02 at sneakemail.com> ---
Safe D and DIP1000 were created for this.

int[] makeRef(return int[] a)
{
    return a;
}

int[] getArray()
{
    int[10] a;
    a []= 42;
    return makeRef(a);
}

void main()
{
    writefln("%s",getArray());
}

Error: returning makeRef(cast(int[])a) escapes a reference to local variable a

--


More information about the Digitalmars-d-bugs mailing list