[Issue 23145] New: Stack allocation of scope variables defeats @safe

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun May 29 00:55:18 UTC 2022


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

          Issue ID: 23145
           Summary: Stack allocation of scope variables defeats @safe
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: safe
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: timon.gehr at gmx.ch

DMD v2.100.0

Compiles even with -dip1000:

---
class D{
    C c;
}
class C {
    D d;
    int x=3;
    this(D d)@safe @nogc{
        d.c=this;
        this.d=d;
    }
}
C foo(D d)@nogc @safe{
    scope c = new C(d); // remove `scope` and program does not crash
    return c.d.c; // escape c
}
void main(){
    import std.stdio;
    writeln(foo(new D)); // segfault
}
---

--


More information about the Digitalmars-d-bugs mailing list