static foreach over constant range in @nogc block

tspike email at
Sat Oct 3 11:18:59 UTC 2020

I came across an issue recently that I’m a little confused by. 
The following program fails to compile under LDC and DMD, though 
it compiles fine under GDC:


     void main()
         static foreach(i; 0 .. 4)
             pragma(msg, i);

Both DMD and LDC report the following error if I try to compile 

     test.d(7): Error: cannot use operator ~= in @nogc delegate 

I was just wondering, is this is a compiler bug or is there a 
reason I'm overlooking preventing this sort of code from 

More information about the Digitalmars-d-learn mailing list