Bug 10221 – foreach(char c; 0..256) doesn't work even though the upper bound is 255

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-31T16:32:00Z
Last change time
2014-02-08T09:22:18Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
thelastmammoth

Comments

Comment #0 by thelastmammoth — 2013-05-31T16:32:55Z
foreach(char c; 0..256) doesn't work even though the upper bound is 255: Error: cannot implicitly convert expression (256) of type int to char Maybe instead disallow: foreach(char c; 0..257) ? Is that a bug, or how would we achieve iterating over all chars without resorting to : foreach(c_; 0..256){ char c=c_.to!char; }
Comment #1 by andrej.mitrovich — 2013-05-31T18:39:10Z
Comment #2 by yebblies — 2013-11-21T07:13:18Z
void test10221() { foreach(char c; 0..256) { } } https://github.com/D-Programming-Language/dmd/pull/2847
Comment #3 by github-bugzilla — 2014-02-08T08:31:18Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/ce5cffc4493db9e9fba57476e564fb7a4a9553eb Fix Issue 10221 - foreach(char c; 0..256) doesn't work even though the upper bound is 255 https://github.com/D-Programming-Language/dmd/commit/d3ea1fb833ca49d56df23a400e4e93e50b5eac2b Merge pull request #2847 from yebblies/issue10221 Issue 10221 - foreach(char c; 0..256) doesn't work even though the upper bound is 255
Comment #4 by bearophile_hugs — 2014-02-08T09:22:18Z
This is a small but quite useful improvement of the D type system.