[Issue 8722] foreach triggers a floating point exception with multidimensional array of a dimension equal to 0

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 25 02:26:18 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8722


monarchdodra at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra at gmail.com


--- Comment #2 from monarchdodra at gmail.com 2012-09-25 02:26:59 PDT ---
Additional information:

The first example makes my dmd 2.060 crash actually (!)

Note that the two examples are not *strictly* equivalent, as
    foreach(element)
will make a copy of each element, whereas:
    foreach ( i; 0 .. array.length )
      whatever( array[i] )
Will access each element by reference.

Changing the first code snippet to:

//-----------------------------
void whatever( T )( in ref T array )
{
  static if ( isArray!( T ) )
    foreach ( ref element; array ) //HERE: REF
      whatever( element );
}


void main()
{
  int[0][2][3] array;
  whatever( array );
}
//-----------------------------

Works.

Either way, there is something wrong in there, if dmd is crashing. Besides, the
code is legit, and should not produce a floating point exception either.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list