False "variable uninitialized" compiler warning in boolean evaluation with -O3
Original Reporter info from Mantis: kluug.net @onpok
-
Reporter name: Ondrej Pokorny
Original Reporter info from Mantis: kluug.net @onpok
- Reporter name: Ondrej Pokorny
Description:
Compiling with -O3, the following code emits a warning:
// function MyOut(out S: string): Boolean;
if MyOut(S) and (S<>'') then
// Warning: Variable "S" of a managed type does not seem to be initialized
Boolean evaluation is always guaranteed to execute from left to right, therefore S must be initialized after MyOut() execution.
Steps to reproduce:
compile the following program with -O3:
fpc OutParamWarning.lpr -O3
program OutParamWarning;
{$mode objfpc}{$H+}
function MyOut(out S: string): Boolean;
begin
S := 'a';
Result := True;
end;
var
S, T: string;
begin
if MyOut(S) and (S<>'') then // warning: BUG
Writeln(S);
MyOut(T);
Writeln(T); // no warning: OK
end.
Additional information:
Compiling with -O2 does not show the warning.
Mantis conversion info:
- Mantis ID: 38103
- Platform: i386-win32
- Version: 3.3.1