actually, this is not a default argument passing bug, this is "CTFE union initializer bug":
import std.stdio;
import std.string;
struct Vector3 {
union {
float[3][1] A;
float[3] flat;
}
string toString() const {
return format(`[%( %s %) ]`, flat);
}
this(in float[] args…) {
flat[] = args[];
}
}
immutable AXIS_Y_1 = Vector3(0, 1, 0);
void main() {
auto n = AXIS_Y_1;
writeln(n);
}
output: [ nan nan nan ]
import std.stdio;
import std.string;
struct Vector3 {
float[3] flat;
string toString() const {
return format(`[%( %s %) ]`, flat);
}
this(in float[] args…) {
flat[] = args[];
}
}
immutable AXIS_Y_1 = Vector3(0, 1, 0);
void main() {
auto n = AXIS_Y_1;
writeln(n);
}
output: [ 0 1 0 ]
Comment #3 by ketmar — 2015-02-08T08:28:32Z
and, hehehe:
import std.stdio;
import std.string;
struct Vector3 {
union {
float[3] flat;
float[3][1] A;
}
string toString() const {
return format(`[%( %s %) ]`, flat);
}
this(in float[] args…) {
flat[] = args[];
}
}
immutable AXIS_Y_1 = Vector3(0, 1, 0);
void main() {
auto n = AXIS_Y_1;
writeln(n);
}
output: [ 0 1 0 ]
so, compiler just unable to see that `A` and `flat` occupies the same space, and takes the default values for the first member of the union. for `A` they are all nans. and for `flat` they are set by CTFE constructor.