www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5725] New: ubyte/ushort infinite foreach loops

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5725

           Summary: ubyte/ushort infinite foreach loops
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



Problem found by Magnus Lie Hetland.
This program produces two infinite loops, DMD 2.052:


void main() {
    alias ubyte T1;
    T1[T1.max + 1] array1;
    foreach (T1 i, _; array1) {}
    alias ushort T2;
    T2[T2.max + 1] array2;
    foreach (T2 i, _; array2) {}
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 10 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5725




Related. This compiles with no errors, and maybe goes in infinite loop:

import std.stdio;
void main() {
    auto array = new int[270];
    foreach (ubyte i, ref x; array)
        x = i;
    writeln(array);
}


If the range of the fixed-sized array is larger than the max number that the
index can represent, then I suggest to raise a compile-time error, just like
this program does:

void main() {
   ubyte x = 270;
}

test.d(2): Error: cannot implicitly convert expression (270) of type int to
ubyte

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 26 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5725




*** Issue 7034 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 16 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5725




*** Issue 8964 has been marked as a duplicate of this issue. ***

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