www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8498] New: inconsistent foreach behaviour in CTFE and at runtime

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8498

           Summary: inconsistent foreach behaviour in CTFE and at runtime
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: timon.gehr gmx.ch



Passes with DMD 2.059, asserts with DMD 2.060:

int fun(){
    int r;
    foreach(i;0..10) r+=i++;
    return r;
}
enum x = fun();
void main(){ assert(fun()==x); }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 02 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8498


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |CTFE, wrong-code
                 CC|                            |clugdbug yahoo.com.au
            Summary|inconsistent foreach        |modifying foreach range
                   |behaviour in CTFE and at    |iterator fails in CTFE
                   |runtime                     |



Here's a reduced test case. There are 10 iterations, even though the iteration
variable is changed.

int fun(){
    int r=0;
    foreach(i;0..10) {
       ++r;
       i= 100; 
       assert(i==100); // ok  -- but doesn't affect the foreach
    }
    return r;
}
static assert(fun() == 1);


Interestingly this is in direct conflict with enhancement bug 6214, which asks
for the behaviour we see in CTFE to be used at run time.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 03 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8498





 Here's a reduced test case. There are 10 iterations, even though the iteration
 variable is changed.
 
 int fun(){
     int r=0;
     foreach(i;0..10) {
        ++r;
        i= 100; 
        assert(i==100); // ok  -- but doesn't affect the foreach
     }
     return r;
 }
 static assert(fun() == 1);
 
 
 Interestingly this is in direct conflict with enhancement bug 6214, which asks
 for the behaviour we see in CTFE to be used at run time.
Interestingly the original bug report/title wasn't as it explicitly took this into account. :o) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 03 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8498


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |philippe.sigaud gmail.com



*** Issue 8614 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 03 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8498




Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/b52dca5a53def60352dbcbf4f398c10abb2cb6b1
Fix issue 8498 modifying foreach range iterator fails in CTFE

This was caused by ignoring assignment to ref variables.
(These guys can only be created by the inliner, or by lowering,
such as happens in foreach).

Also fixes bug 7658: assignment to ref in foreach.
Also fixes bug 8539: nested functions, ref parameter, -inline.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 01 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8498


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
         Resolution|                            |FIXED


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