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

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


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

Ketmar Dark <ketmar at ketmar.no-ip.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ketmar at ketmar.no-ip.org

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

--


More information about the Digitalmars-d-bugs mailing list