Bug 9565 – Index of static array should not print literal suffix

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-21T20:56:00Z
Last change time
2013-09-28T19:33:49Z
Keywords
diagnostic, pull
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2013-02-21T20:56:52Z
Index type of static array is always size_t, so suffix is not only just redundant, but also is harmful for platform independent diagnostic message. alias T = int[10]; pragma(msg, T); // should print `int[10]` rather than `int[10u]` or `int[10LU]`. Similar problem exists in IndexExp and SliceExp int[] arr; pragma(msg, (arr[0]).stringof); // arr[cast(uint)0] pragma(msg, (arr[0..1]).stringof); // arr[cast(uint)0..cast(uint)1] // should print arr[0] and arr[0..1] But, it would need to keep "cast(...)" output for some cases pragma(msg, (arr[int.min]).stringof); // arr[cast(uint)-2147483648]
Comment #1 by bearophile_hugs — 2013-02-22T03:05:12Z
(In reply to comment #0) > But, it would need to keep "cast(...)" output for some cases > > pragma(msg, (arr[int.min]).stringof); // arr[cast(uint)-2147483648] I'd even like D to statically refuse indexing an array with a -2147483648 index :-)
Comment #2 by andrej.mitrovich — 2013-02-22T11:16:16Z
(In reply to comment #0) > Index type of static array is always size_t, so suffix is not only just > redundant, but also is harmful for platform independent diagnostic message. I think the reason it's there is to make the actual literal valid, because AFAIK you actually need to append "LU" for some big literals. But maybe we could remove the suffixes for small literals.
Comment #3 by k.hara.pg — 2013-03-01T02:35:57Z
(In reply to comment #2) > (In reply to comment #0) > > Index type of static array is always size_t, so suffix is not only just > > redundant, but also is harmful for platform independent diagnostic message. > > I think the reason it's there is to make the actual literal valid, because > AFAIK you actually need to append "LU" for some big literals. But maybe we > could remove the suffixes for small literals. You are right. if the dimension is in (long.max, ulong.max], "LU" suffix is necessary. (If LU is not there, "signed integer overflow" error will occur in lexer).
Comment #4 by k.hara.pg — 2013-09-03T17:30:22Z
Comment #5 by github-bugzilla — 2013-09-04T07:58:50Z
Comment #6 by github-bugzilla — 2013-09-15T00:36:45Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/d1ab5012b00c34023ed715a0c22ecb3bd8b674ff fix Issue 9565 - Index of static array should not print literal suffix Static array type index is always size_t, so unnecessary suffix is harmful for platform independent diagnostic message. (Note that: In 64bit platform, size_t is ulong, and if the value is greater than long.max, suffix is *necessary*.) Same problem exists in IndexExp and SliceExp printing. https://github.com/D-Programming-Language/dmd/commit/724566600724314a27dbf7bfd63aeda12f27780d Merge pull request #2522 from 9rnsr/fix9565 Issue 9565 - Index of static array should not print literal suffix
Comment #7 by github-bugzilla — 2013-09-28T19:33:49Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/1c1633533435c48aac8811f41dabb4009da61bd0 Fixup for issue 9565 Remove unnecessary else block so right not it's never used. https://github.com/D-Programming-Language/phobos/commit/d744bec6d4500d6cb6f43011beefc7765dd0e5ce Merge pull request #1605 from 9rnsr/fix9565 Fixup for issue 9565 - cleanup of #1544