[Issue 15544] New: Escaping fields to a heap delegate must be disallowed in @safe code
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Sun Jan 10 07:00:08 PST 2016
    
    
  
https://issues.dlang.org/show_bug.cgi?id=15544
          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 at puremagic.com
          Reporter: sludwig at 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); };
 }
}
---
--
    
    
More information about the Digitalmars-d-bugs
mailing list