[Issue 15575] New: Wrong value for static immutable struct with union
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Jan 17 16:28:56 PST 2016
https://issues.dlang.org/show_bug.cgi?id=15575
Issue ID: 15575
Summary: Wrong value for static immutable struct with union
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: cpicard at openmailbox.org
DMD v2.069, no flag, crashes when dealing with the following code:
-----------------------------------------------------------------------------
struct Color {
union {
ubyte[4] components;
struct {
ubyte r;
ubyte g;
ubyte b;
ubyte a;
}
}
this(ubyte red, ubyte green, ubyte blue, ubyte alpha=255) {
if(__ctfe)
this.components[0] = cast(ubyte) red;
else
this.r = cast(ubyte) red;
this.g = cast(ubyte) green;
this.b = cast(ubyte) blue;
this.a = cast(ubyte) alpha;
}
}
static immutable colorA = Color(0xcc, 0x88, 0x00);
void main(string[] args) {
pragma(msg, colorA.components);
// [cast(ubyte)204u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u]
pragma(msg, colorA);
// Color([cast(ubyte)204u, cast(ubyte)0u, cast(ubyte)0u, cast(ubyte)0u], ,
// cast(ubyte)136u, cast(ubyte)0u, cast(ubyte)255u, )
}
-----------------------------------------------------------------------------
The message is:
t.d(32): Error: Internal Compiler Error: null field components
test.d(32): while evaluating pragma(msg, colorA.components)
Color(, , cast(ubyte)136u, cast(ubyte)0u, cast(ubyte)255u, )
LDC doesn't produce an error message but produces garbage instead.
--
More information about the Digitalmars-d-bugs
mailing list