[fpc-devel] Dangerous optimization in CASE..OF

Ondrej Pokorny lazarus at kluug.net
Sun Jul 2 20:16:26 CEST 2017


On 02.07.2017 19:39, Florian Klämpfl wrote:
> So this means:
>
> var
>    b : boolean;
>
> begin
>    b:=boolean(3);
>    if b then
>      writeln(true)
>    else if not(b) then
>      writeln(false)
>    else
>      writeln(ord(b));
> end.
>
> writes 3 in delphi?

IMO you picked up a Delphi compiler bug/undocumented feature (call it as 
you want). "if boolean(3) then A" executes A contrary to the 
documentation - the docs say something different then the compiler does. 
You should not use it as an argument but create an issue report on 
Embarcadero's Quality Central so that they either fix the documentation 
or fix the compiler.

Whereas:
case boolean(3) of
   True: A;
   False: B;
else
   C;
end;

is documented to execute C and the compiler executes C => good.

Ondrej



More information about the fpc-devel mailing list