On 22.04.2018 10:46, Luca Olivetti wrote:
El 22/04/18 a les 06:53, Ondrej Pokorny ha escrit:

My goal is to get the best from it. If disallowing of IS/AS for enums with holes in FPC modes is a requirement for applying the patch, I am OK with this sacrifice.

Why disallow it instead of simply checking if it's one of the valid values?

What do you understand with "valid values"? Do you mean "declared values"?

Reasons why I haven't worked on checking declared values in assigned enums:

1.) It's not "simply checking". The check would be much more complex than a simple low-high check. At least I cannot do that for an arbitrary assigned enum - I admit I don't have enough compiler knowledge and motivation. I don't use assigned enums myself.

2.) I am not even 100% sure what valid values are in assigned enums. At least no FPC developer has confirmed yet what they understand with valid values for assigned enums. I assume only "declared values" are "valid values" (unlike in Delphi where the whole range is valid) but nobody from FPC team has confirmed it yet (or I missed it).

3.) It is potentially very dangerous if the IS/AS operator behaved differently in Delphi and FPC mode. I feel that modes are more about syntax sugar and not about substantially different behavior. The clean way to go is to write a compiler intrinsic that checks for declared values only (in all modes) and a different intrinsic to check for valid range (in all modes) and make the IS/AS operator to duplicate one of these intrinsics on all modes, eventually disabling it in some modes for unclear preconditions.

+++

So: if Sven (or the FPC team) think that the IS/AS check for valid range of assigned enums doesn't belong to FPC mode, it's better to disallow it there and not change its behavior.

+++

And as always: feel free to extend the patch and add support for checking only declared values in assigned enums - if you have the skill and motivation and you believe it can and will be applied to FPC trunk. (I write this without any offense.)

Ondrej
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to