www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18357] New: can break immutable with postblit

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

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

----
struct S
{
    int* x;
    this(this)  safe { *x = 13; }
}

void main()  safe
{
    immutable int* x = new int(42);
    assert(*x == 42); /* passes */
    auto s = immutable S(x);
    auto s2 = s; /* should be rejected */
    assert(*x == 42); /* fails */
}
----

--
Feb 02 2018