www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - static foreach over constant range in nogc block

reply tspike <email gamedevgp.net> writes:
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?
Oct 03 2020
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
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; }(); }
Oct 03 2020
parent reply tspike <email gamedevgp.net> writes:
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?
Oct 03 2020
parent reply Paul Backus <snarwin gmail.com> writes:
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
Oct 03 2020
parent reply tspike <email gamedevgp.net> writes:
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.
Oct 03 2020
parent reply Paul Backus <snarwin gmail.com> writes:
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".
Oct 03 2020
parent tspike <email gamedevgp.net> writes:
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!
Oct 03 2020