Bug 7058 – static initializer for structs doesn't respect init values of members
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-12-02T18:50:00Z
Last change time
2015-06-09T05:11:57Z
Keywords
wrong-code
Assigned to
nobody
Creator
hoganmeier
Comments
Comment #0 by hoganmeier — 2011-12-02T18:50:33Z
void main()
{
import std.stdio;
vec3 v = {1.5f, 2}; // with vec3(1.5f, 2) z becomes 0
writeln(v);
}
struct vec3
{
// union
// {
// struct
// {
float x = 0;
float y = 0;
float z = 0;
// }
// float[3] cell;
// }
}
$ dmd -run vector.d
vec3(1.5, 2, nan)
Comment #1 by hoganmeier — 2011-12-02T19:04:09Z
Interestingly enough, if you add a tuple it only respects the first value at all:
void main()
{
import std.stdio;
vec3 v = {1.5f, 1.f, 0.5f};
writeln(v);
}
template Tuple(T...)
{
alias T Tuple;
}
template Repeat(T, int count)
{
static if (!count)
alias Tuple!() Repeat;
else
alias Tuple!(T, Repeat!(T, count-1)) Repeat;
}
struct vec3
{
union
{
struct
{
float x = 0;
float y = 0;
float z = 0;
}
// float[3] cell;
Repeat!(float, 3) tuple;
}
}
$ dmd -run vector.d
vec3(1.5, nan, nan, 1.5, nan, nan)
Comment #2 by clugdbug — 2012-05-29T01:02:58Z
*** This issue has been marked as a duplicate of issue 4967 ***