Thread overview
static foreach over constant range in @nogc block
Oct 03
tspike
Oct 03
tspike
Oct 03
tspike
Oct 03
tspike
October 03
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?
October 03
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; }();
}
October 03
On Saturday, 3 October 2020 at 12:43:01 UTC, Timon Gehr wrote:
>
> It's a compiler bug, the same as this one:
>
> @nogc:
> void main(){
>     static immutable x = { int[] a; a~=1; return a; }();
> }

Ah, thank you for the quick reply! Do you know if this bug has already been reported?
October 03
On Saturday, 3 October 2020 at 14:02:08 UTC, tspike wrote:
> On Saturday, 3 October 2020 at 12:43:01 UTC, Timon Gehr wrote:
>>
>> It's a compiler bug, the same as this one:
>>
>> @nogc:
>> void main(){
>>     static immutable x = { int[] a; a~=1; return a; }();
>> }
>
> Ah, thank you for the quick reply! Do you know if this bug has already been reported?

https://issues.dlang.org/show_bug.cgi?id=18439


October 03
On Saturday, 3 October 2020 at 14:12:21 UTC, Paul Backus wrote:
> https://issues.dlang.org/show_bug.cgi?id=18439

Perfect! Thanks for getting back to me so quickly.
October 03
On Saturday, 3 October 2020 at 14:17:45 UTC, tspike wrote:
> On Saturday, 3 October 2020 at 14:12:21 UTC, Paul Backus wrote:
>> https://issues.dlang.org/show_bug.cgi?id=18439
>
> Perfect! Thanks for getting back to me so quickly.

FYI I am not Timon Gehr, the person who originally replied to you, but I was able to find the bug report by searching Bugzilla for "static foreach nogc".
October 03
On Saturday, 3 October 2020 at 14:19:27 UTC, Paul Backus wrote:
> On Saturday, 3 October 2020 at 14:17:45 UTC, tspike wrote:
>> On Saturday, 3 October 2020 at 14:12:21 UTC, Paul Backus wrote:
>>> https://issues.dlang.org/show_bug.cgi?id=18439
>>
>> Perfect! Thanks for getting back to me so quickly.
>
> FYI I am not Timon Gehr, the person who originally replied to you, but I was able to find the bug report by searching Bugzilla for "static foreach nogc".

Sorry about getting your name wrong, I got a little overzealous when snipping off the quoted part of my post! If I find anything else I think might be a bug I'll have to try searching Bugzilla before I ask about it on the forums. Thanks again for your help, I'm amazed at how fast everyone is to help out here!