[Issue 20505] New: [DIP1000] Static array allows to escape refewrences to stack variables

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 15 08:26:31 UTC 2020


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 at puremagic.com
          Reporter: pro.mathias.lang at 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).

--


More information about the Digitalmars-d-bugs mailing list