digitalmars.D.bugs - [Issue 6206] New: Pure function not called in comma expression in for loop increment
- d-bugmail puremagic.com (37/37) Jun 24 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6206
- d-bugmail puremagic.com (13/13) Jun 24 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6206
http://d.puremagic.com/issues/show_bug.cgi?id=6206 Summary: Pure function not called in comma expression in for loop increment Product: D Version: D2 Platform: Other OS/Version: Linux Status: NEW Keywords: wrong-code Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: bugzilla kyllingen.net --- Comment #0 from Lars T. Kyllingstad <bugzilla kyllingen.net> 2011-06-24 02:21:32 PDT --- Test case: struct S { int i = 0; void incr() pure { ++i; } } void main() { S s; for (int j=0; j<10; s.incr(), ++j) { } assert (s.i == 10); // fails } The assert should pass, but it fails iff S.incr() is marked as pure. (In fact, S.i is never increased at all in this case.) Note that moving '++j' into the loop body makes the bug disappear. It seems the call to s.incr() must be part of a comma expression for the bug to manifest. While seemingly obscure, this has some very real consequences. For example, it means std.algorithm.equal() doesn't work with ranges that have a pure popFront(). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 24 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6206 kennytm gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |kennytm gmail.com Resolution| |DUPLICATE --- Comment #1 from kennytm gmail.com 2011-06-24 02:28:28 PDT --- Exactly the same as bug 5798, which turns out not completely fixed. *** This issue has been marked as a duplicate of issue 5798 *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 24 2011