On Sunday, 29 September 2013 at 18:01:01 UTC, monarch_dodra wrote:
On Sunday, 29 September 2013 at 17:35:33 UTC, andrea9940 wrote:
Thanks for the answer, I will use the aliases; however I just
tried my code on codepad and surprising it worked without
errors http://codepad.org/hp0YxIi7
I think there is a bug in there somewhere though:
//----
struct V{
union {
struct {
float x = 0;
float y = 0;
}
struct {
float r;
float g;
}
}
}
void main() {
assert(V.init.x == 0 && V.init.y == 0); //Passes
V v1 = V.init;
assert(v1 is V.init); //Passes
V v2 = V(); // OR simply use: V v2;
assert(v2 is V.init); //Fails
}
//----
That just isn't right. "T.init" and "T()" is supposed to be
equivalent (bar static opCall).
Also, I'm 99% confident that when initializing a union, the
first member (in this case, the struct), is the one that gets
initialized. *fully* initialized.
So my conclusion is that there is something wrong in the
construction sequence/defintion, and that this bug is
definitely valid.
Definitely something very wrong:
struct V
{
union
{
struct
{
float x = 0;
float y = 0;
int a = 3;
}
struct
{
float r;
float g;
int d;
}
}
}
import std.stdio;
void main()
{
writeln("V(", V.init.x, ", ", V.init.y, ", ", V.init.a, ", ",
V.init.r, ", ", V.init.g, ", ", V.init.d, ")");
writeln(V.init);
writeln(V(V.init.x, V.init.y, V.init.a));
}
V(0, 0, 3, 0, 0, 3)
V(0, nan, 0, 0, nan, 0)
V(0, 0, 3, 0, 0, 3)
WAT???