static foreach over constant range in @nogc block
Timon Gehr
timon.gehr at gmx.ch
Sat Oct 3 12:43:01 UTC 2020
On 03.10.20 13:18, tspike wrote:
> 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:
>
> @nogc:
>
> void main()
> {
> static foreach(i; 0 .. 4)
> {
> pragma(msg, i);
> }
> }
>
> Both DMD and LDC report the following error if I try to compile it:
>
> test.d(7): Error: cannot use operator ~= in @nogc delegate
> test.main.__lambda1
>
> I was just wondering, is this is a compiler bug or is there a reason I'm
> overlooking preventing this sort of code from compiling?
It's a compiler bug, the same as this one:
@nogc:
void main(){
static immutable x = { int[] a; a~=1; return a; }();
}
More information about the Digitalmars-d-learn
mailing list