www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15544] New: Escaping fields to a heap delegate must be


          Issue ID: 15544
           Summary: Escaping fields to a heap delegate must be disallowed
                    in  safe code
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: sludwig outerproduct.org

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); }; } } --- --
Jan 10 2016