[Issue 22128] New: opApply delegate can escape scope without duly invoking GC allocation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jul 18 23:33:09 UTC 2021


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

          Issue ID: 22128
           Summary: opApply delegate can escape scope without duly
                    invoking GC allocation
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/
                OS: All
            Status: NEW
          Severity: major
          Priority: P3
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: eyal at weka.io

@safe:

import std;

struct S {
    int delegate(char x) @safe _dlg;
    @safe @nogc
    int opApply(int delegate(char x) @safe dlg) {
        _dlg = dlg;
        return 0;
    }
}

@safe unittest {
    S s;
    @safe
    void f() {
        int i = 1;
        foreach(x; s) { writeln(x, ": ", i); }
        // BUG disappears if this is used instead:
        // s.opApply((char x){ writeln(x, ": ", i); return 0; });
        // because then the frame of 'f' comes from GC correctly (non-scoped
delegate)
    }
    f();
    s._dlg('x');
    writeln("Again:");
    s._dlg('y');
}

--


More information about the Digitalmars-d-bugs mailing list