[fpc-devel] [Suggestion] Enumeration range-check intrinsic
Ondrej Pokorny
lazarus at kluug.net
Fri Jul 5 16:55:34 CEST 2019
On 05.07.2019 16:51, Pierre Muller wrote:
> Just one point from current compiler implementation:
>
> in trunk/fpcsrc/compiler/ninl.pas (around line 3180)
>
> in_pred_x,
> in_succ_x:
> begin
> set_varstate(left,vs_read,[vsf_must_be_valid]);
> resultdef:=left.resultdef;
> if is_ordinal(resultdef) or is_typeparam(resultdef) then
> begin
> if (resultdef.typ=enumdef) and
> (tenumdef(resultdef).has_jumps) and
> not(m_delphi in current_settings.modeswitches) and
> not(nf_internal in flags) then
> CGMessage(type_e_succ_and_pred_enums_with_assign_not_possible);
> end
>
>
> This means that using pred() or succ() intrinsics on enumerated types with
> holes will generate a Compile Time Error.
Only for non-Delphi modes, see: not(m_delphi in
current_settings.modeswitches)
> 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 ...
See this thread:
https://lists.freepascal.org/pipermail/fpc-devel/2019-May/040865.html
Ondrej
More information about the fpc-devel
mailing list