Bug 15544 – Escaping fields to a heap delegate must be disallowed in @safe code

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-01-10T15:00:00Z
Last change time
2017-01-16T23:26:40Z
Keywords
pull, safe
Assigned to
nobody
Creator
sludwig

Comments

Comment #0 by sludwig — 2016-01-10T15:00:08Z
From https://github.com/rejectedsoftware/vibe.d/issues/570 The following code currently compiles fine, but results in a dangling reference to "this.x" when the delegate gets called after the life time of the originating "Test" instance. At least in @safe code, taking the address of a struct field of "this" within a non-scoped delegate must instead result in a compile-time error. --- void delegate() @safe _del; struct Test { int x = 42; @safe void test() { _del = { assert(x == 42); }; } } ---
Comment #1 by bugzilla — 2016-08-24T07:00:07Z
Comment #2 by github-bugzilla — 2016-11-01T10:35:06Z
Commit pushed to scope at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/e61378a715e01e58365df753985d1178d5ba4bd4 fix Issue 15544 - Escaping fields to a heap delegate must be disallowed in @safe code
Comment #3 by github-bugzilla — 2016-12-31T18:15:33Z
Commit pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/e61378a715e01e58365df753985d1178d5ba4bd4 fix Issue 15544 - Escaping fields to a heap delegate must be disallowed in @safe code
Comment #4 by github-bugzilla — 2017-01-16T23:24:12Z
Commit pushed to newCTFE at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/e61378a715e01e58365df753985d1178d5ba4bd4 fix Issue 15544 - Escaping fields to a heap delegate must be disallowed in @safe code