foreach loop over retro can crash gdmd

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Thu Jun 28 10:16:21 PDT 2012


Hello all,

The following code crashes my version of GDC (4.6.3) when I try and compile it:

////////////////////////////////////////////////////
import std.range, std.stdio;

void main()
{
       double[] a = [ 0, 1, 2, 3, 4, 5 ];

       foreach(i, x; retro(a))
             writeln(x);
}
////////////////////////////////////////////////////

It specifically requires the two-variable foreach() loop: if I just have,

       foreach(x; retro(a))

then it compiles and runs without problem.  If I specify the variable types,

       foreach(size_t i, double x; retro(a))

then it fails to compile with an error:

       retro.d:7: Error: cannot infer argument types

This last error also occurs if I try to compile the original code with the 
latest (from GitHub) DMD.

I imagine that means that the crash is also fixed in the latest GDC, but just 
checking :-)

Thanks & best wishes,

      -- Joe


More information about the D.gnu mailing list