[Issue 19178] New: Static initialization of 2d static arrays in structs produces garbage or doesn't compile sometimes

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Aug 19 16:49:48 UTC 2018


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

          Issue ID: 19178
           Summary: Static initialization of 2d static arrays in structs
                    produces garbage or doesn't compile sometimes
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dkorpel at live.nl

Doing this:
```
struct T {
    int[3][3] arr = 2;
}
```
Results in:
cannot implicitly convert expression 2 of type int to int[3][3]

While it's okay to do this in a function body. Furthermore:
```
import std.stdio: writeln;

struct T {
    int[3][3] arr = [2, 1];
    this(int stub) {
        arr[0][0] = 9;
    }
}

void main() {
    T.init.writeln;
    T(0).writeln;
}
```
Outputs this:
```
T([[2, 1, 0], [0, 0, 118033674], [723976, 0, 4100]])
T([[9, 2, 2], [1, 1, 1], [0, 0, 0]])
```

The .init value is incorrect and has garbage.

Related: https://issues.dlang.org/show_bug.cgi?id=13799
"Whole-array initialization for static fixed-size arrays of arrays too"

--


More information about the Digitalmars-d-bugs mailing list