Bug 11147 – Nested structs in a union are not correctly initialized

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-30T01:43:00Z
Last change time
2013-09-30T11:33:10Z
Keywords
industry, pull, wrong-code
Assigned to
nobody
Creator
andrea.9940

Comments

Comment #0 by andrea.9940 — 2013-09-30T01:43:43Z
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)
Comment #1 by andrea.9940 — 2013-09-30T01:47:05Z
> 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; } } }
Comment #2 by monarchdodra — 2013-09-30T03:36:34Z
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.
Comment #3 by k.hara.pg — 2013-09-30T04:34:10Z
Comment #4 by github-bugzilla — 2013-09-30T11:33:03Z
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