digitalmars.D.bugs - [Issue 19856] New: [aApplycd2]: foreach (int) doesn't work on
- d-bugmail puremagic.com (38/38) May 09 2019 https://issues.dlang.org/show_bug.cgi?id=19856
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 puremagic.com Reporter: ibuclaw 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. --
May 09 2019