www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21517] New: Functions nested within `inout` functions can

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

          Issue ID: 21517
           Summary: Functions nested within `inout` functions can
                    reinterpret `inout`
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: timon.gehr gmx.ch

int* g(immutable(int)* y)pure  safe{
    int* foo(inout(int)* x)pure  safe{
        int* bar(inout(int)* delegate(inout int)pure  safe z){
            return z(2);
        }
        return bar((inout t)=>x);
    }
    return foo(y);
}

void main()pure  safe{
    auto x=new immutable int;
    int* y=g(x);
    assert(x is y); // passes, bad
}

--
Dec 30 2020