0

Boolean(Integer) cast check

il2 9 years ago 0

Please add a check for very likely erroneous Boolean(Integer) cast because except Boolean(0)=FALSE and Boolean(1)=TRUE all other Boolean(Integer) are UNDEFINED and not TRUE as one may assume. Actually, Ord(Boolean(N))=N! This is undefined behavior and very error-prone.


Consider this example:

program BooleanTest;

{$APPTYPE CONSOLE}

uses SysUtils;

begin

Writeln(Boolean(0) = TRUE); //results in FALSE - OK

Writeln(Boolean(1) = TRUE); //results in TRUE - OK

Writeln(Boolean(4) = TRUE); //results in FALSE - FAIL!

Writeln(Ord(Boolean(4))); //results in 4 - OUCH!

end.


https://quality.embarcadero.com/browse/RSP-13972