TryStrToInt returns true despite overflow
The documentation for TryStrToInt states:
TryStrToInt tries to convert the string S to an integer, and returns True if this was successful. In that case the converted integer is returned in I. If the conversion failed, (an invalid string, or the value is out of range) then False is returned.
However, in my tests the function returns true even if the result overflows:
{$mode objfpc}
program Project1;
uses
SysUtils;
var
Value: Integer;
Success: Boolean;
begin
Success := TryStrToInt('7795000000', Value);
if Success then
WriteLn('Conversion succeeded: ', Value)
else
WriteLn('Conversion failed.');
end.
Expected result:
Conversion failed.
Actual result:
Conversion succeeded: -794934592
The demo code was compiled using FPC 3.2.2 on Arch Linux x86_64:
fpc fpbug.pas
Am I misunderstanding something?