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
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to