[Issue 2562] New: foreach over uninitialized array fails in CTFE

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 7 06:38:30 PST 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2562

           Summary: foreach over uninitialized array fails in CTFE
           Product: D
           Version: 1.039
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: clugdbug at yahoo.com.au


int foo()
{
   int [] xxx;
   foreach(q; xxx) {}
   return 1;
}

static assert(foo());
----
bug.d(8): Error: cannot evaluate foo() at compile time
bug.d(8): static assert  (foo()) is not evaluatable at compile
time

Workarounds: (1) Replace the foreach with for:
   for (int q=0; q<xxx.length; ++q) {}
(2) Initialize the array
   int [] xxx = [];

This is NOT the same as issue 1375, which appears to be fixed.


-- 



More information about the Digitalmars-d-bugs mailing list