Unnecessary warning for functions that return dynamic arrays in the new version of FPC
Original Reporter info from Mantis: SergeAnvarov @SergeAnvarov
-
Reporter name: Serge Anvarov
Original Reporter info from Mantis: SergeAnvarov @SergeAnvarov
- Reporter name: Serge Anvarov
Description:
When SetLength(Result, ...) is called inside a function, then compiler issues a warning: "Function result variable of a managed type does not seem to be initialized"
Steps to reproduce:
{$MODE OBJFPC}
{$LONGSTRINGS ON}
// Only this function issues a warning
function TestA1: TBoundArray;
begin
SetLength(Result, 100);
end;
procedure TestA2(var Result: TBoundArray);
begin
SetLength(Result, 100);
end;
procedure TestA3;
var
NotUsed: TBoundArray;
begin
SetLength(NotUsed, 100);
NotUsed := NotUsed;
end;
function TestS1: string;
begin
SetLength(Result, 100);
end;
procedure TestS2(var Result: string);
begin
SetLength(Result, 100);
end;
procedure TestS3;
var
NotUsed: string;
begin
SetLength(NotUsed, 100);
NotUsed := NotUsed;
end;
var
A: TBoundArray = nil;
S: string = '';
begin
TestA1;
TestA2(A);
TestA3;
TestS1;
TestS2(S);
TestS3;
end.
Additional information:
According to the documentation, the result of a function that returns a managed data type behaves as an additional variable with a var modifier. That is, TestA1 and TestA2 must be the same. Indeed, the same code is generated for them, but only TestA1 issues a warning.
With FPC 3.0.4 code in "Steps To Reproduce" not issue warning.
With the "-Oodfa" compiler option, no warning is issued.
Mantis conversion info:
- Mantis ID: 35475
- Version: 3.3.1
- Monitored by: » Fr0sT (Fr0sT)