Bug 6079 – [CTFE] Array index out of bound detection is off-by-one

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Mac OS X
Creation time
2011-05-31T01:59:00Z
Last change time
2011-06-01T22:49:53Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
kennytm

Comments

Comment #0 by kennytm — 2011-05-31T01:59:48Z
Test case: ------------------------ static assert({ int[] x = [1,2,3,4]; x[4] = 1; return true; }()); ------------------------ In 2.052 this is correctly rejected, but in 2.053 this is wrongly accepted. Changing the [4] to [5] will make the code fail to compile. There should be some off-by-one error introduced between the two versions.
Comment #1 by kennytm — 2011-05-31T02:39:16Z
The bug was introduced in commit 4120b86*, I believe this is because of if (indexToModify > destarraylen) // ^ should be >=. *: https://github.com/D-Programming-Language/dmd/commit/4120b86f67eace7a7b930a6ceca823d2088deefd#L0R2728
Comment #2 by clugdbug — 2011-06-01T22:49:53Z