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

Ondrej Pokorny lazarus at kluug.net
Sat Jul 6 09:40:31 CEST 2019


On 05.07.2019 22:44, J. Gareth Moreton wrote:
>
> In the meantime, I've extended your AS/IS patch over here 
> <https://bugs.freepascal.org/view.php?id=33603> to create efficient 
> code for x86 platforms, although currently it only does a range check 
> and won't correctly handle enumerations with holes.  If non-contiguous 
> enumerations are going to be allowed, we'll need to design an 
> algorithm that can cover these holes with the smallest number of 
> Boolean conditions.
>
IMO handling holes in enumerations is just a pure waste of time and 
energy. Delphi documents them as valid and the FPC compiler handles them 
as valid as well. IMO it is just an unnecessary extra added limitation 
to disable IS/AS on them. Furthermore they are used mainly for very 
specific needs, so are very marginal. The effort to make this work just 
doesn't pay off.

Btw. you get a "project1.lpr(7,10) Warning: Case statement does not 
handle all possible cases" in the program below anyway:

program Project1;
type
   THoleEnum = (two=2, four=4);
var
   E: THoleEnum;
begin
   case E of
     two: ;
     four: ;
   end;
end.

What will you do now, disable case-of for enumerations with holes 
because the compiler cannot handle the holes correctly in the strict FPC 
POV way?

Ondrej

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190706/312ff69e/attachment-0001.html>


More information about the fpc-devel mailing list