Bug 14440 – [REG2.067] [CTFE] Wrong values set in a matrix constructor

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-04-12T11:33:00Z
Last change time
2015-06-17T21:04:42Z
Keywords
CTFE, pull, wrong-code
Assigned to
nobody
Creator
devw0rp

Attachments

IDFilenameSummaryContent-TypeSize
1512test.dA reduced test case.application/x-dsrc916

Comments

Comment #0 by devw0rp — 2015-04-12T11:33:59Z
Created attachment 1512 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 2.066. 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.
Comment #1 by ag0aep6g — 2015-04-12T12:28:32Z
Reduced further: struct Matrix { int[1][2] array2D; this(int dummy) { array2D[0][0] = 1; array2D[1][0] = 2; /* writes over array2D[0][0] */ } } static assert(Matrix(0).array2D[0][0] == 1); /* fails */
Comment #2 by k.hara.pg — 2015-04-12T12:30:24Z
Comment #3 by github-bugzilla — 2015-04-12T13:37:15Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/7b64c8d9e45c93be287c8a5b0f5f14ec566cebaa fix Issue 14440 - [CTFE] Wrong values set in a matrix constructor https://github.com/D-Programming-Language/dmd/commit/444cc4e4cd4246395c2a12058a8de8ec90f134ed Merge pull request #4583 from 9rnsr/fix14440 [REG2.067] Issue 14440 - [CTFE] Wrong values set in a matrix constructor
Comment #4 by github-bugzilla — 2015-04-17T14:09:54Z
Commit pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/56c8b67cb084f575c34555cb19dfae12e1b2a726 Merge pull request #4583 from 9rnsr/fix14440 [REG2.067] Issue 14440 - [CTFE] Wrong values set in a matrix constructor
Comment #5 by github-bugzilla — 2015-04-26T00:04:42Z
Comment #6 by github-bugzilla — 2015-06-17T21:04:42Z