[Issue 17682] New: can break immutable with destructor

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


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

          Issue ID: 17682
           Summary: can break immutable with destructor
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: accepts-invalid, safe
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: ag0aep6g at gmail.com

Should be rejected:

----
struct S
{
    int* p;
    ~this() @safe { if (p) *p = 13; }
}

void main() @safe
{
    immutable int* i = new int(42);
    assert(*i == 42); /* passes */
    {
        auto s = immutable S(i);
    }
    assert(*i == 42); /* fails; it's 13 now */
}
----

--


More information about the Digitalmars-d-bugs mailing list