1906 – foreach cannot use index with large arrays

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1906 - foreach cannot use index with large arrays
Summary: foreach cannot use index with large arrays
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P2 normal
Assignee: Walter Bright
URL:
Keywords: spec, wrong-code
Depends on:
Blocks:
Reported: 2008年03月11日 07:20 UTC by Jerry Quinn
Modified: 2015年06月09日 05:15 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Jerry Quinn 2008年03月11日 07:20:09 UTC
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 Jerry Quinn 2008年03月11日 07:25:10 UTC
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 Christian Kamm 2008年03月11日 10:22:19 UTC
I think language specification issues are usually filed against dmd and marked with the 'spec' keyword.
Comment 3 Walter Bright 2008年05月11日 04:14:25 UTC
Fixed dmd 1.029 and 2.013


AltStyle によって変換されたページ (->オリジナル) /