Bug 16566 – hasLength should enforce that length has type size_t

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-10-01T00:42:22Z
Last change time
2018-01-05T13:29:15Z
Assigned to
No Owner
Creator
Andrei Alexandrescu

Comments

Comment #0 by andrei — 2016-10-01T00:42:22Z
Currently hasLength verifies that length has the exact type size_t. Currently it's more permissive allowing anything implicitly convertible to ulong. See some discussion in https://github.com/dlang/phobos/pull/4815. There is a gray area of 64-bit length on 32-bit system but I doubt much code could work that way.
Comment #1 by meapineapple — 2016-10-01T00:47:38Z
What is the rationale for disallowing other numeric primitives for length, or types that act like numeric primitives?
Comment #2 by issues.dlang — 2016-10-05T19:26:45Z
(In reply to Sophie from comment #1) > What is the rationale for disallowing other numeric primitives for length, > or types that act like numeric primitives? It complicates code considerably for it to have to worry about length being anything other than size_t, and the vast majority of existing code assumes that length is size_t. Anything else just plain doesn't play well with a lot of code, and making it play well would require being very careful about how length was handled every time it was used. At one point, iota was changed so that it supported ulong for length so that ranges over long or ulong could have a length and contain the full range of values for long or ulong on a 32-bit system. It caused more trouble than it was worth, and we changed it so that iota's length was always size_t once again. The newsgroup discussion that Andrei opened up in relation to this bug report: http://forum.dlang.org/post/[email protected]
Comment #3 by dfj1esp02 — 2016-10-06T11:55:01Z
(In reply to Jonathan M Davis from comment #2) > http://forum.dlang.org/post/[email protected] Looks like he considers non-numeric types for length. Numeric types have no such problems.
Comment #4 by dlang-bugzilla — 2017-06-07T13:51:41Z
What about e.g. ranges representing files over 4GB on 32-bit architectures?
Comment #5 by andrei — 2017-06-07T13:54:14Z
(In reply to Vladimir Panteleev from comment #4) > What about e.g. ranges representing files over 4GB on 32-bit architectures? Those are not supported.
Comment #6 by github-bugzilla — 2017-06-16T17:21:24Z
Commit pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/72f395084373b8c15518def33216485301e8de8a Fix Issue 16566 - hasLength should enforce that length has type size_t
Comment #7 by github-bugzilla — 2017-06-17T11:35:12Z
Commit pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/72f395084373b8c15518def33216485301e8de8a Fix Issue 16566 - hasLength should enforce that length has type size_t
Comment #8 by github-bugzilla — 2018-01-05T13:29:15Z
Commit pushed to dmd-cxx at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/72f395084373b8c15518def33216485301e8de8a Fix Issue 16566 - hasLength should enforce that length has type size_t