DMD version: 2.063.2 The value of all variables in V should be zero, but the output shows they aren't. --------------- struct V { union { struct { float x = 1; float y = 1; float z = 1; } struct { float r; float g; float b; } } } import std.stdio; void main() { writeln("V(", V.init.x, ", ", V.init.y, ", ", V.init.z, ", ", V.init.r, ", ", V.init.g, ", ", V.init.b, ")"); writeln(V.init); writeln(V(V.init.x, V.init.y, V.init.z)); } --------------- V(0, 0, 0, 0, 0, 0) V(0, nan, nan, 0, nan, nan) V(0, 0, 0, 0, 0, 0)
> struct V { > union { > struct { > float x = 1; > float y = 1; > float z = 1; > } > struct { > float r; > float g; > float b; > } > } > } I posted the wrong code, the correct one is: struct V { union { struct { float x = 0; float y = 0; float z = 0; } struct { float r; float g; float b; } } }
I wanted to add that this: void main() { assert(V.init is V()); } It would *appear* that the compiler is confused as to *what* the initial state of V is.
https://github.com/D-Programming-Language/dmd/pull/2603
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/a8d1d0911a10e2b941aba2a4de56c5a8b3f8dcea fix Issue 11147 - Nested structs in a union are not correctly initialized https://github.com/D-Programming-Language/dmd/commit/6e8d1f888c6d8e159e5145b5649252708976fb22 Merge pull request #2603 from 9rnsr/fix11147 Issue 11147 - Nested structs in a union are not correctly initialized