[Issue 14862] New: Constructor of overlapped struct does not initialize correctly global variables
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Aug 2 00:54:51 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14862
Issue ID: 14862
Summary: Constructor of overlapped struct does not initialize
correctly global variables
Product: D
Version: D2
Hardware: x86
OS: Windows
Status: NEW
Severity: blocker
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: rumbu at rumbu.ro
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; }
}
}
--
More information about the Digitalmars-d-bugs
mailing list