[Issue 15205] New: Incorrect struct init via union array
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Oct 15 08:28:41 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=15205
Issue ID: 15205
Summary: Incorrect struct init via union array
Product: D
Version: D2
Hardware: x86_64
OS: Windows
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: h1054820 at trbvm.com
Tested with: D2.068.1 and D2.069.b
struct Foo
{
this( float x_, float y_ )
{
// option A
//x = x_;
//y = y_;
// option B
v[0] = x_;
v[1] = y_;
}
union
{
struct
{
float x = 0;
float y = 0;
}
float[2] v;
}
}
struct Bar
{
Foo foo = Foo( 1, 2 );
}
Bar bar;
Bar baz = bar.init;
printf( "bar: %f, %f\n", bar.foo.x, bar.foo.y );
printf( "baz: %f, %f\n", baz.foo.x, baz.foo.y );
-------------------------------------------------
prints (with option B):
bar: 0.000000, 0.000000 // BUG??
baz: 1.000000, 2.000000
prints (with option A):
bar: 1.000000, 2.000000
baz: 1.000000, 2.000000
--
More information about the Digitalmars-d-bugs
mailing list