Thread overview
[Issue 1906] New: foreach cannot use index with large arrays
Mar 11, 2008
d-bugmail
Mar 11, 2008
d-bugmail
Mar 11, 2008
d-bugmail
May 11, 2008
d-bugmail
March 11, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1906

           Summary: foreach cannot use index with large arrays
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: jlquinn@optonline.net


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.


-- 

March 11, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1906





------- Comment #1 from jlquinn@optonline.net  2008-03-11 07:25 -------
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.


-- 

March 11, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1906


kamm-removethis@incasoftware.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |spec, wrong-code




------- Comment #2 from kamm-removethis@incasoftware.de  2008-03-11 10:22 -------
I think language specification issues are usually filed against dmd and marked with the 'spec' keyword.


-- 

May 11, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1906


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #3 from bugzilla@digitalmars.com  2008-05-11 04:14 -------
Fixed dmd 1.029 and 2.013


--