Bug 6222 – A problem with iota() using size_t

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-06-29T13:33:00Z
Last change time
2012-04-22T19:31:28Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-06-29T13:33:50Z
With DMD 2.053 this apparently goes in infinite loop: import std.range; void main() { string s; foreach (i; iota(0, s.length, 3)) {} } What I expect: the foreach loop to loop zero times instead. See also bug 4603
Comment #1 by eco — 2012-04-20T19:55:20Z
Comment #2 by github-bugzilla — 2012-04-22T17:54:03Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/6b92abb0449e6af80f68beb9fa1311346397bfaf fix Issue 6222 - A problem with iota() using size_t If the common type of begin and end is unsigned and end is 0 the private member pastEnd ends up being unsigned.max due to "pastEnd - 1" (used to make end not inclusive) which results in iota behaving incorrectly. A simple change to always make an empty range when begin==end prevents this. Also fixed and clarified the documentation. https://github.com/D-Programming-Language/phobos/commit/b1252f35afc019c37f334d274c257a25a4e0035f Merge pull request #547 from eco/iota-unsigned-odd fix Issue 6222 - A problem with iota() using size_t