Bug 8722 – foreach triggers a floating point exception with multidimensional array of a dimension equal to 0

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2012-09-25T01:56:00Z
Last change time
2013-11-25T02:33:35Z
Keywords
ice
Assigned to
nobody
Creator
blooh_

Comments

Comment #0 by blooh_ — 2012-09-25T01:56:23Z
The code below triggers a floating point exception, not sure if it's too be expected? // ------------------------------ import std.stdio; import std.traits; void whatever( T )( in ref T array ) { static if ( isArray!( T ) ) foreach ( element; array ) whatever( element ); } void main() { int[0][2][3] array; whatever( array ); } // ------------------------------ If changing the loop to // ------------------------------ foreach ( i; 0 .. array.length ) whatever( array[i] ); // ------------------------------ it works fine. Also changing the array type to int[0][2] ie. works as well.
Comment #1 by blooh_ — 2012-09-25T02:10:09Z
Did I really write "too be"...? Where's the edit button!? :)
Comment #2 by monarchdodra — 2012-09-25T02:26:59Z
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.
Comment #3 by yebblies — 2013-11-24T05:23:31Z
Can anyone reproduce?
Comment #4 by monarchdodra — 2013-11-25T02:04:35Z
(In reply to comment #3) > Can anyone reproduce? This is still failing for me (win32, 2.064.2). I assume you tried Linux 64? I'm getting a dmd crash: Unhandled exception at 0x0053d9e6 in dmd.exe: 0xC0000094: Integer division by zero. So this is now an ICE for me. I don't have a development environment here, so I can't tell which line is actually doing this.
Comment #5 by yebblies — 2013-11-25T02:08:53Z
(In reply to comment #4) > (In reply to comment #3) > > Can anyone reproduce? > > This is still failing for me (win32, 2.064.2). I assume you tried Linux 64? > Nope, win32 with 2.065 master. Please have a go with the latest master if you can.
Comment #6 by monarchdodra — 2013-11-25T02:33:35Z
(In reply to comment #5) > (In reply to comment #4) > > (In reply to comment #3) > > > Can anyone reproduce? > > > > This is still failing for me (win32, 2.064.2). I assume you tried Linux 64? > > > > Nope, win32 with 2.065 master. Please have a go with the latest master if you > can. It indeed works with DMD v2.065 DEBUG. I guess I'll close this then.