Bug 14862 – Constructor of overlapped struct does not initialize correctly global variables

Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-08-02T07:54:00Z
Last change time
2015-09-06T17:05:32Z
Keywords
CTFE, pull
Assigned to
nobody
Creator
rumbu

Comments

Comment #0 by rumbu — 2015-08-02T07:54:51Z
struct S { union { struct { uint hi, lo; } ulong data; } this(ulong data) { this.data = data; } } immutable S sglobal = S(123UL); //not run enum S senum = S(123UL); void main() { S slocal = S(123UL); assert(slocal.data == 123UL); assert(senum.data == 123UL); assert(sglobal.data == 123UL); //fail, in fact it's 0 } BUT by inversing the overlapped fields, the struct it's initialized properly: struct S { union { ulong data; struct { uint hi, lo; } } }
Comment #1 by k.hara.pg — 2015-08-06T02:04:04Z
Comment #2 by github-bugzilla — 2015-09-06T17:05:32Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/1fda8abadb1a9d068ea1d0fb236e3383a6b23e7b fix Issue 14862 - Constructor of overlapped struct does not initialize correctly global variables https://github.com/D-Programming-Language/dmd/commit/1445df52a1ed5b50f16c6b7aad3dabbcf7297265 Merge pull request #4863 from 9rnsr/fix14862 Issue 14862 - Constructor of overlapped struct does not initialize correctly global variables