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

Florian Klämpfl florian at freepascal.org
Sun Jul 16 22:39:41 CEST 2017


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.




More information about the fpc-devel mailing list