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

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jul 25 03:04:05 PDT 2017


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

ag0aep6g at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |safe

--- Comment #1 from ag0aep6g at gmail.com ---
Also possible in @safe code:

----
struct S
{
    immutable(int)* p;
}

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

void main() @safe
{
    immutable int* p = new int(42);
    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