The following code fails with dmd v2.094.1 under Linux x86_64:
int main()
{
ubyte[10] buf;
size_t pos = 0;
size_t num = 5;
buf[pos++] += num;
assert(pos == 1);
assert(buf[0] == 5);
assert(buf[1] == 0);
return 0;
}
Instead pos == 2, buf[0] == 0 and buf[1] == 5.
The same code works as expected with ldc and gdc.
Comment #1 by dlang-bot — 2020-11-25T17:34:15Z
@BorisCarvajal created dlang/dmd pull request #11997 "Fix Issue 21424 - Variable is incremented twice" fixing this issue:
- Fix Issue 21424 - Variable is incremented twice
https://github.com/dlang/dmd/pull/11997
Comment #2 by dlang-bot — 2020-12-05T14:34:15Z
dlang/dmd pull request #11997 "Fix Issue 21424 - Variable is incremented twice" was merged into master:
- 7b7cd2f86faf68bb108fae70863c159204f481b5 by Boris Carvajal:
Fix Issue 21424 - Variable is incremented twice
https://github.com/dlang/dmd/pull/11997