[fpc-devel] Dangerous optimization in CASE..OF

Florian Klämpfl florian at freepascal.org
Sun Jul 16 23:11:59 CEST 2017


Am 16.07.2017 um 22:39 schrieb Florian Klämpfl:
> Am 16.07.2017 um 22:15 schrieb Martok:
>>
>> However:
>> ---------------------------
>> {$mode objfpc}
>> type
>>   TExplEnum = (a=1, b=3, c=5, d=7);
>>   TSubEnum = a..d;
>>   TEnArr = array[TSubEnum] of Byte;
>>
>> begin
>>   WriteLn('SizeOf(TEnArr) = ', SizeOf(TEnArr));
>>   WriteLn('Low(TEnArr) = ', Low(TEnArr), ', ', Ord(Low(TEnArr)));
>>   WriteLn('High(TEnArr) = ', High(TEnArr), ', ', Ord(High(TEnArr)));
>> end.
>> ---------------------------
>> SizeOf(TEnArr) = 7
>> Low(TEnArr) = a, 1
>> High(TEnArr) = d, 7
>> ---------------------------
>>
>> That difference was unexpected. At least for me.
> 
> Indeed, this is a bug. IMO the declaration of TSubEnum should not be allowed.

I made a patch and tested it, however, this causes regressions in our tests, so I am not sure if it
should be changed.




More information about the fpc-devel mailing list