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).