D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6222 - A problem with iota() using size_t
Summary: A problem with iota() using size_t
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-29 13:33 UTC by bearophile_hugs
Modified: 2012-04-22 19:31 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-06-29 13:33:50 UTC
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 2 github-bugzilla 2012-04-22 17:54:03 UTC
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