Bug 1906 – foreach cannot use index with large arrays

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2008-03-11T07:20:00Z
Last change time
2015-06-09T05:15:22Z
Keywords
spec, wrong-code
Assigned to
bugzilla
Creator
jlquinn

Comments

Comment #0 by jlquinn — 2008-03-11T07:20:09Z
In D, array length is specified to be size_t, which allows for arrays up to the size of memory. However, the indexing form of foreach only permits an int or uint as the index variable. This will likely result in a silent bug used on an array w/ more than 4G elements in a 64 bit environment. For example: char[] x; x.length = 0x2_0000_0000L; // fill the array foreach (int i, char c; x) do_something(i, c); foreach should be able to support a size_t in the index variable location.
Comment #1 by jlquinn — 2008-03-11T07:25:10Z
I put this bug against DMD, but it's really a language definition issue. It might make sense to provide a separate component to separate issues with the language spec from those with the compiler implementation.
Comment #2 by kamm-removethis — 2008-03-11T10:22:19Z
I think language specification issues are usually filed against dmd and marked with the 'spec' keyword.
Comment #3 by bugzilla — 2008-05-11T04:14:25Z
Fixed dmd 1.029 and 2.013