View Issue Details

IDProjectCategoryView StatusLast Update
0034169FPCCompilerpublic2020-05-17 19:43
ReporterFr0sT Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
Product Version3.1.1 
Summary0034169: SetLength produces warning 5089 Local variable of a managed type does not seem to be initialized
DescriptionFPC rev. 58686 produces warning 5089 if SetLength is called with a local variable and it is the 1st usage of this variable. But is there correct way to avoid it? SetLength was always enough to init a variable.
Steps To Reproduceprocedure test;
var
  arr: array of WideChar;
begin
  SetLength(arr, 100);
end;
Tagscompiler, warnings
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Relationships

has duplicate 0034171 closedMichael Van Canneyt SetLength() for dynamic array gives warning 

Activities

Michael Van Canneyt

2018-08-22 15:52

administrator   ~0110234

Last edited: 2018-08-22 15:53

View 2 revisions

Setlength uses a var parameter. This is no different from other cases of var parameter usage.

In trunk you can initialize your variable with

Var
  Arr: array of widechar = ();

So the following program:

program ta2,

Var
  Arr: array of widechar = ();

begin
  setlength(arr,100);
end.

will not produce any warnings:

home:~> fpc ta2.pp -vwhn
Hint: Start of reading config file /home/michael/.fpc.cfg
Hint: End of reading config file /home/michael/.fpc.cfg

Marco van de Voort

2018-09-06 11:33

manager   ~0110534

(as said on the maillist) That recommendation doesn't work in Delphi mode.

Moreover, even for objfpc I consider it a temporary workaround, code changes should not be needed to silence unneeded warnings.

Kirinn

2020-05-17 19:43

reporter   ~0122885

These warnings didn't happen with 3.0.4, but are happening when testing 3.2.0 RC1. This makes me hesitant to upgrade, since I have a moderate codebase that's now generating quite a few of these hints, which are clearly incorrect - a local non-function-result managed variable is always guaranteed to be initialized to zero.

SetLength could be a special case to var parameter usage, and not generate this warning, or the automatic initialization should be recognised as equivalent to an explicit "var := NIL". But I appreciate this is a big request, so maybe it's not feasible.

Issue History

Date Modified Username Field Change
2018-08-22 14:24 Fr0sT New Issue
2018-08-22 14:25 Fr0sT Tag Attached: compiler
2018-08-22 14:25 Fr0sT Tag Attached: warnings
2018-08-22 15:52 Michael Van Canneyt Note Added: 0110234
2018-08-22 15:52 Michael Van Canneyt Status new => resolved
2018-08-22 15:52 Michael Van Canneyt Resolution open => no change required
2018-08-22 15:52 Michael Van Canneyt Assigned To => Michael Van Canneyt
2018-08-22 15:53 Michael Van Canneyt Note Edited: 0110234 View Revisions
2018-08-22 16:15 Michael Van Canneyt Relationship added has duplicate 0034171
2018-09-06 11:33 Marco van de Voort Note Added: 0110534
2020-05-17 19:43 Kirinn Note Added: 0122885