Bug 23111 – stack-allocated array escapes in @safe code

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-05-16T04:05:01Z
Last change time
2022-05-16T11:35:45Z
Assigned to
No Owner
Creator
Susan

Comments

Comment #0 by su+dlangissues — 2022-05-16T04:05:01Z
the following code escapes a stack-allocated array, making it unsafe. auto foo() @nogc nothrow pure @safe { import std.array : staticArray; import std.algorithm : map; auto test = [1, 2, 3].staticArray; return test[].map!(x => x); } when run with -preview=dip1000, it correctly fails to compile.
Comment #1 by dkorpel — 2022-05-16T11:35:45Z
The dip1000 flag was put in place to avoid code breakage. Still allowing slices to static arrays allocated on the stack in @safe code was a deliberate decision. This will be fixed by the dip1000 by default transition in 2.101, and the snippet already doesn't compile anymore on master (though it might be reduced to a deprecation for this release).