[fpc-devel] [Suggestion] Enumeration range-check intrinsic

Ondrej Pokorny lazarus at kluug.net
Fri Jul 5 22:13:47 CEST 2019


On 05.07.2019 16:51, Pierre Muller wrote:
> This means that using pred() or succ() intrinsics on enumerated types with
> holes will generate a Compile Time Error.
>
>    To be consistent, I would propose that we also generate
> a Compile Time Error if 'is' or 'as' keyword is used on such a type,
> unless there is a code that really check that the value is not in
> one of the holes ...

I have to strongly disagree here. We need the IS/AS operators to prevent 
undefined behavior. And if undefined behavior is only outside the 
low/high bounds of the enumeration values and not within the holes - 
then the IS/AS that checks only the bounds is very consequent indeed. 
It's also consequent with the case-of statement for an enum with holes. 
(See the thread I linked before.)

Ondrej



More information about the fpc-devel mailing list