www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19881] New: Escaping reference to local through return scope

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

          Issue ID: 19881
           Summary: Escaping reference to local through return scope with
                    -dip1000 and  safe
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: simen.kjaras gmail.com

 safe int* fun(return scope int* input) {
    int local = 123;
    input = &local; // This line shouldn't compile

    return input;
}

 safe void main() {
    import std.stdio;
    int* p;
    p = fun(p);
    (*p).writeln; // 123
    (*p).writeln; // Random garbage
}

--
May 16 2019