Thread overview
Static Array with negative index results in a strange error-message
Apr 23, 2018
Dgame
Apr 23, 2018
Dgame
Apr 23, 2018
Dgame
April 23, 2018
char[-1] c;

results in

Error: char[18446744073709551615LU] size 1 * 18446744073709551615 exceeds 0x7fffffff size limit for static array

Should we fix that? A negative index should be IMO detected sooner/with a cleaner error message.
April 23, 2018
On 4/23/18 9:32 AM, Dgame wrote:
> char[-1] c;
> 
> results in
> 
> Error: char[18446744073709551615LU] size 1 * 18446744073709551615 exceeds 0x7fffffff size limit for static array
> 
> Should we fix that? A negative index should be IMO detected sooner/with a cleaner error message.

Hm.. at least it's detected. I actually don't think the message is wrong: -1 is a valid size_t literal, and results in that number.

if you did:

enum size_t x = -1;
char[x] c;

You would get the same result, and I don't know how we would fix that.

-Steve
April 23, 2018
On Monday, 23 April 2018 at 13:48:07 UTC, Steven Schveighoffer wrote:
> On 4/23/18 9:32 AM, Dgame wrote:
>> char[-1] c;
>> 
>> results in
>> 
>> Error: char[18446744073709551615LU] size 1 * 18446744073709551615 exceeds 0x7fffffff size limit for static array
>> 
>> Should we fix that? A negative index should be IMO detected sooner/with a cleaner error message.
>
> Hm.. at least it's detected. I actually don't think the message is wrong: -1 is a valid size_t literal, and results in that number.
>
> if you did:
>
> enum size_t x = -1;
> char[x] c;
>
> You would get the same result, and I don't know how we would fix that.
>
> -Steve

C's error message is

error: 'c' declared as an array with a negative size
    char c[-1];

That is more understandable.
April 23, 2018
It's really fun playing around:

char[int.max - 1] c;

results in

Internal error: dmd/backend/cgcod.c 634

with DMD 2.079. Guess I or somebody else should report this.


April 23, 2018
On 4/23/18 11:09 AM, Dgame wrote:
> It's really fun playing around:
> 
> char[int.max - 1] c;
> 
> results in
> 
> Internal error: dmd/backend/cgcod.c 634
> 
> with DMD 2.079. Guess I or somebody else should report this.
> 
> 

Yes, this is an ICE (Internal compiler error). Those should ALWAYS be reported.

-Steve