Bug 19856 – [aApplycd2]: foreach (int) doesn't work on BigEndian targets
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-05-09T09:48:49Z
Last change time
2019-06-09T14:10:34Z
Keywords
pull
Assigned to
No Owner
Creator
Iain Buclaw
Comments
Comment #0 by ibuclaw — 2019-05-09T09:48:49Z
In the following code, the index `i` is always zero.
---
void checkChars(ref string s) @safe pure
{
dchar c;
int n = -1;
foreach (int i, dchar d; s)
{
if (!isChar(d))
{
c = d;
n = i;
break;
}
}
}
---
This is because the foreach body is delegatized, and the internal runtime function passed it a size_t*.
The fix of course is to use ptrdiff_t for the index type instead, however, the compiler should warn/error about such code.
There's already a deprecation path for other kinds of arrays, char/dchar/wchar seems to have been forgotten when fixing issue 16976.
Comment #1 by dlang-bot — 2019-05-11T13:55:26Z
@ibuclaw created dlang/dmd pull request #9770 "Fix Issue 19856 - [aApplycd2]: foreach (int) doesn't work on BigEndian targets" fixing this issue:
- Fix Issue 19856 - [aApplycd2]: foreach (int) doesn't work on BigEndian targets
https://github.com/dlang/dmd/pull/9770
Comment #2 by dlang-bot — 2019-05-13T00:53:29Z
dlang/dmd pull request #9770 "Fix Issue 19856 - [aApplycd2]: foreach (int) doesn't work on BigEndian targets" was merged into master:
- a07acfd88c92228dbc7b1ae630099722088cfc3a by Iain Buclaw:
Fix Issue 19856 - [aApplycd2]: foreach (int) doesn't work on BigEndian targets
https://github.com/dlang/dmd/pull/9770
Comment #3 by dlang-bot — 2019-06-09T14:10:34Z
dlang/dmd pull request #10009 "[dmd-cxx] Fix Issue 19856 - [aApplycd2]: foreach (int) doesn't work on BigEndian targets" was merged into dmd-cxx:
- 9fcce71bd507fa57ce17d8173b6f73d320a8122b by Iain Buclaw:
Fix Issue 19856 - [aApplycd2]: foreach (int) doesn't work on BigEndian targets
https://github.com/dlang/dmd/pull/10009