www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15193] New: DIP25 (implementation): Lifetimes of temporaries

https://issues.dlang.org/show_bug.cgi?id=15193

          Issue ID: 15193
           Summary: DIP25 (implementation): Lifetimes of temporaries
                    tracked incorrectly
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: timon.gehr gmx.ch

The following code corrupts memory.

enum N=100;
ref int[N] foo() safe{
    struct S{
        int[N] x;
        ref int[N] bar()return{ return x; }
    }
    return S().bar();
}

ref int[N] baz() safe{ return foo(); }
void bang(ref int[N] x) safe{ x[]=0x25BAD; }
void main() safe{ bang(baz()); }


(Contrast this with:
ref int foo() safe{
    struct S{
        int x;
        ref int bar()return{ return x; }
    }
    S s;
    return s.bar();
} 

This is rejected correctly.)

--
Oct 12 2015