www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20505] New: [DIP1000] Static array allows to escape

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

          Issue ID: 20505
           Summary: [DIP1000] Static array allows to escape refewrences to
                    stack variables
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: accepts-invalid, safe
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: pro.mathias.lang gmail.com

For me this is similar to 17764, but the test case is much more simple.

```
import std.stdio;

void main ()  safe
{
    auto x = bar();
    writeln(x);
}

char[] bar()  safe  nogc
{
    char[128] a;
    char[][2] arr = [a, a];
    return foo(arr);
}

char[] foo(scope char[][] arr)  safe  nogc
{
    return arr[0];
}
```

Compiled with:
path/to/dmd -preview=dip1000 -run foo.d
Will print garbage. Tested with v2.090.0 and HEAD
(v2.090.0-beta.1-51-g49dfbe54f, commit of 2020-01-08).

--
Jan 15 2020