Example code: import std.stdio; void main() { uint[] values = [0, 1, 2, 3, 4, 5, 6, 7]; uint offset = 2; writeln(values[offset .. offset += 2]); writeln(offset); } Outputs: [] 4 Expected output: [2, 3] 4 Works correctly in LDC 2.063.2 (thanks DPaste). Doesn't work in DMD 2.065 or 2.066.1
Code like this is ugly, if I see code like this I refactor it immediately: values[offset .. offset += 2] Into two lines like: values[offset .. offset + 2] offset += 2;
(In reply to Richard Cattermole from comment #0) > Works correctly in LDC 2.063.2 (thanks DPaste). > Doesn't work in DMD 2.065 or 2.066.1 dmd 2.063 prints same output with 2.066. I guess that the behavior difference comes from the the difference of glue layer implementations of LDC and DMD (currently DMD, LDC, and GCC have their own glue layers to fit to each backends).
https://github.com/D-Programming-Language/dmd/pull/4345 As far as I see, old versions of dmd have same behavior with git-head, so it's not a dmd regression. But, the current behavior is contrary to the deterministic evaluation order, so I think it should be fixed. Downgrade importance to 'blocker'.
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/4fe170a3a3f2d5c3a4751f2c3e90ac6380583aab fix Issue 14040 - Doesn't use assignment in slice If upr has any side effects, lwr should be copied to temporary always. https://github.com/D-Programming-Language/dmd/commit/13f41930d43825f5fa88dbfb994946b67160656e Merge pull request #4345 from 9rnsr/fix14040 Issue 14040 - Doesn't use assignment in slice
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/4fe170a3a3f2d5c3a4751f2c3e90ac6380583aab fix Issue 14040 - Doesn't use assignment in slice https://github.com/D-Programming-Language/dmd/commit/13f41930d43825f5fa88dbfb994946b67160656e Merge pull request #4345 from 9rnsr/fix14040