[Issue 19856] New: [aApplycd2]: foreach (int) doesn't work on BigEndian targets
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu May 9 09:48:49 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=19856
Issue ID: 19856
Summary: [aApplycd2]: foreach (int) doesn't work on BigEndian
targets
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: ibuclaw at gdcproject.org
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.
--
More information about the Digitalmars-d-bugs
mailing list