[Issue 18738] [scope] scope delegates can be escaped via closure
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Tue Dec  6 06:03:21 UTC 2022
    
    
  
https://issues.dlang.org/show_bug.cgi?id=18738
andy.pj.hanson at gmail.com changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andy.pj.hanson at gmail.com
--- Comment #2 from andy.pj.hanson at gmail.com ---
I think is a similar bug: 
```
@safe:
import std.stdio : writeln;
void main() {
        int* x = escape();
        writeln("x is ", *x); // x is 1
        *x = 5;
        escape();
        writeln("x is ", *x); // x is 1
}
pure @nogc nothrow:
int* escape() {
        int* res;
        callbackWithPointer([1, 2, 3], (int* i) { res = i; });
        return res;
}
void callbackWithPointer(T)(scope T[] a, scope void delegate(T*) @safe @nogc
pure nothrow f) {
        f(&a[0]);
}
```
In this case a `pure` function `escape` appears to return a pointer to global
state.
`f(&a[0])` probably shouldn't be allowed. The delegate expects a `T*` but gets
a `scope T*`.
--
    
    
More information about the Digitalmars-d-bugs
mailing list