Bug 19178 – Static initialization of 2d static arrays in structs produces garbage or doesn't compile sometimes
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2018-08-19T16:49:48Z
Last change time
2022-07-25T13:27:29Z
Keywords
pull
Assigned to
No Owner
Creator
Dennis
Comments
Comment #0 by dkorpel — 2018-08-19T16:49:48Z
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"
Comment #1 by dlang-bot — 2022-01-07T12:39:33Z
@dkorpel created dlang/dmd pull request #13498 "Fix issue 19178 - Static initialization of 2d static arrays in structs" fixing this issue:
- Fix issue 19178 - Static initialization of 2d static arrays in structs produces garbage or doesn't compile sometimes
https://github.com/dlang/dmd/pull/13498
Comment #2 by dkorpel — 2022-06-21T15:44:45Z
*** Issue 23137 has been marked as a duplicate of this issue. ***
Comment #3 by dlang-bot — 2022-07-25T13:27:29Z
dlang/dmd pull request #13498 "Fix issue 19178 - Static initialization of 2d static arrays in structs" was merged into master:
- 548eb527475eb67307944ca3acdd280efcd3b829 by Dennis Korpel:
Fix issue 19178 - Static initialization of 2d static arrays in structs
https://github.com/dlang/dmd/pull/13498