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

Ondrej Pokorny lazarus at kluug.net
Sun Jul 2 18:26:19 CEST 2017


On 02.07.2017 18:20, Jonas Maebe wrote:
> 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.

Allow me a stupid question: how to convert an integer to enum with range 
checking? A cast does not generate range checking, if I am not mistaken:

program Project1;

type
   TEnum = (one, two);

{$R+}
var
   I: Integer;
   E: TEnum;
begin
   I := 2;
   E := TEnum(I); // <<< I want a range check error here
   Writeln(Ord(E));
end.

Ondrej



More information about the fpc-devel mailing list