www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24609] New: Array of struct with immutable field implicitly

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

          Issue ID: 24609
           Summary: Array of struct with immutable field implicitly
                    converts to void[]
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: nick geany.org

void main()  system
{
    S[] a = [S(5)];
    //a[0] = S(0); // error, modifying immutable member of S

    void[] va = a; // need to disallow
    va[] = [0]; // corrupt a[0]
    assert(a[0].i == 5); // fails
}

struct S
{
    const int i;
}

Should be disallowed with -preview=fixImmutableConv.

--
Jun 15