[Issue 14140] Bad codegen when variable used as default argument

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Feb 8 00:28:32 PST 2015


https://issues.dlang.org/show_bug.cgi?id=14140

--- Comment #3 from Ketmar Dark <ketmar at ketmar.no-ip.org> ---
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.

--


More information about the Digitalmars-d-bugs mailing list