www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17682] New: can break immutable with destructor

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 puremagic.com
          Reporter: ag0aep6g 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 */
}
----

--
Jul 25 2017