www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21478] New: Setting a default value to an object field which

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

          Issue ID: 21478
           Summary: Setting a default value to an object field which is a
                    2D array may cause memory corruption
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ogion.art gmail.com

Trying to access `map` results in segfault. 

class O {
    //int[2][2] array = [[0, 0], [0, 0]]; // works fine

    // also works fine:
    /+
    int[2][2] array;
    this() { array = [0, 0]; }
    +/

    int[2][2] array = [0, 0]; // corrupts `map`

    int[string] map;
}
void main() {
    auto o = new O();
    o.map["one"] = 1; // crashes
}

The bug is present in all version of DMD and not present in LDC.

--
Dec 13 2020