[Issue 19111] Returning a reference to local array results in garbage
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jul 23 02:10:19 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=19111
Mike Franklin <slavo5150 at yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |safe
CC| |slavo5150 at yahoo.com
--- Comment #1 from Mike Franklin <slavo5150 at yahoo.com> ---
Using `@safe` with `-dip1000` seems to catch the error:
import std.stdio;
@safe:
int[] makeRef(int[] a)
{
return a;
}
int[] getArray()
{
int[10] a;
a []= 42;
return makeRef(a);
}
void main()
{
writefln("%s",getArray());
}
$ dmd -dip1000 test.d
https://run.dlang.io/is/hIoDsB
onlineapp.d(14): Error: reference to local variable a assigned to non-scope
parameter a calling `onlineapp.makeRef`
--
More information about the Digitalmars-d-bugs
mailing list