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

Jonas Maebe jonas at freepascal.org
Sun Jul 2 18:20:12 CEST 2017


On 02/07/17 11:59, Yury Sidorov wrote:
> Indeed, I've done some tests and found out that when range checking is 
> enabled enums are not checked at all. Even array access with enum index 
> is not checked.
> According to docs enums should be range checked:
> https://www.freepascal.org/docs-html/prog/progsu65.html#x72-710001.2.65

Range checking code is generated for operations involving enums if, 
according to the type system, the enum can be out of range. Just like 
with integer sub-range types.

E.g., this generates a range check error:

{$r+}
type
   tenum = (ea,eb,ec,ed);
   tsubenum = eb..ec;
var
   arr: array[tsubenum] of byte;
   index: tenum;
begin
   index:=ed;
   writeln(arr[index]);
end.


Jonas



More information about the fpc-devel mailing list