[Issue 14618] New: can break immutable with inout and a delegate

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat May 23 12:42:44 PDT 2015


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

          Issue ID: 14618
           Summary: can break immutable with inout and a delegate
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: ag0aep6g at gmail.com

struct S
{
    immutable(int)* p;
}

inout(int)* f(inout S s)
{
    inout(int)* result;
    auto dg = (inout(int)* p) {result = p;};
    dg(s.p);
    return result;
}

void main()
{
    immutable int x = 42;
    immutable int* p = &x;
    assert(*p == 42); /* passes */
    scope(exit) assert(*p == 42); /* fails */
    int* m = f(S(p)); /* uh-oh */
    *m = 13; /* writing over immutable *p */
}

--


More information about the Digitalmars-d-bugs mailing list