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

J. Gareth Moreton gareth at moreton-family.com
Tue Jul 2 21:48:25 CEST 2019


I should probably test this myself, but if you, say, read a value from a 
file directly into a variable of type TEnumType, will your patch return 
False for "if (Value is TEnumType) then" if Value, despite being 
TEnumType, contains an invalid value?  No problem if it isn't, just that 
you would have to read an Integer-type first then typecast it.

Gareth aka. Kit

On 02/07/2019 20:32, Ondrej Pokorny wrote:
> On 02.07.2019 21:15, Michael Van Canneyt wrote:
>> Don't forget to check the post of Ondrej.
>>
>> Personally, I think using 'as' to convert an integer to an enum with 
>> range
>> check is still the best approach. It does not require new intrinsics 
>> (far
>> too many of those already) and does what it says. To simply check if an
>> integer is a valid enum, I think 'is' would be equally suitable.
>
> The latest patch in https://bugs.freepascal.org/view.php?id=33603 
> supports bot AS and IS operators. Yes, the first patch was only about 
> the AS-operator and the issue summary is about AS only as well. You 
> know - nobody is perfect and I didn't realize the IS-operator was 
> suitable there too in the very beginning. The mind&development 
> progress can be read from the ML thread.
>
> Ondrej
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>
>

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



More information about the fpc-devel mailing list