www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23445] New: Can leak scope variable through delegate context

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

          Issue ID: 23445
           Summary: Can leak scope variable through delegate context
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: accepts-invalid, safe
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: timon.gehr gmx.ch

With DMD v2.101.0-beta.1, the following code is accepted:

int global;
int* foo(scope int* p) safe{
    auto dg=(return scope int* q) safe return scope{
        return p;
    };
    return dg(&global);
}

auto qux() safe{
    int x=10;
    int* p=&x;
    int* q=foo(p);
    return q;
}

void main() safe{
    import std.stdio;
    auto p=qux();
    version(SMASH_STACK) writeln("smashing stack");
    writeln(*p);
}

--
Oct 30 2022