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

           Summary: foreach parameter with number range is always ref
           Product: D
           Version: D2
          Platform: Other
        OS/Version: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: d...@dawgfoto.de


--- Comment #0 from d...@dawgfoto.de 2011-09-12 10:19:15 PDT ---
void main() {
  size_t cnt;
  foreach(ulong n; 0 .. 10)
  {
    ++n;
    ++cnt;
  }
  assert(cnt == 10);

  cnt = 0;
  foreach(ref ulong n; 0 .. 10)
  {
    ++n;
    ++cnt;
  }
  assert(cnt == 5);
}

---

As this is rewritten in terms of a for loop all writes to n will
alter the loop.
A hidden copy of n is needed for non-ref parameters to match the range
foreach semantic.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to