Leak-detection of references to scoped class instances

Per Nordlöw per.nordlow at gmail.com
Sun Nov 24 12:37:45 UTC 2019


Why doesn't DMD detect invalid out-of-scope references to scoped 
class instances?

Example:

@safe:

class C
{
@safe pure:
     this()
     {
     }
     int x;
}

@trusted unittest
{
     C f()
     {
         import std.typecons : scoped;
         auto x = scoped!C();
         return x;
     }
     auto c = f();
     c.x = 42;                   // invalid memory access
}



More information about the Digitalmars-d-learn mailing list