www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14440] New: CTFE Regression: Wrong values set in a matrix


          Issue ID: 14440
           Summary: CTFE Regression: Wrong values set in a matrix
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: regression
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: devw0rp gmail.com

Created attachment 1512
  --> https://issues.dlang.org/attachment.cgi?id=1512&action=edit
A reduced test case.

This is a strange bug. In my dstruct library, I use a constructor which takes
an array of arguments with a fixed size for creating matrices in my library. So
you can write a constructor like this.

auto matrix = Matrix!(int, 3, 3)(1, 2, 3, 4, 5, 6, 7, 8, 9);

So the matrix can be created on the stack directly with no heap allocation,
and then it offers operations like addition and multiplication, etc.

One of my unit tests caught a CTFE regression where 'enum' is used instead of
auto. So
when the matrix is created at runtime, the 2D array held within rightly becomes
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]. However, when 'enum' is used, the array
becomes [[7, 8, 9], [7, 8, 9], [7, 8, 9]]. This used to work just fine in

I have attached a reduced test case to this bug report. Curiously, I tried
using a function instead of a constructor in a struct, and the function worked.
So the bug seems to be somehow tied to the constructor.

Apr 12 2015