www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14238] New: DIP25: escape checks can be circumvented with


          Issue ID: 14238
           Summary: DIP25: escape checks can be circumvented with delegate
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: schuetzm gmx.net

The following code compiles with the -dip25 switch:

    alias Fn = ref int delegate();

    ref int foo(scope Fn fn) {
        return fn();

    ref int bar() {
        int x;
        ref int baz() {
                return x;
        return foo(&baz);

    void main(string[] args) {
        import std.stdio;
        int x;
        writefln("&x = %s", &x);
        int* p = &bar();
        writefln("p  = %s", p);

&x = 7FFFF64F0728
p  = 7FFFF64F0708

As can be seen, `p` points to a location further down the stack.

Mar 02 2015