View Issue Details

IDProjectCategoryView StatusLast Update
0036973FPCCompilerpublic2020-04-26 10:25
ReporterIan Hickson Assigned ToSven Barth  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionwon't fix 
Summary0036973: bogus 'Function result variable of a managed type does not seem to be initialized' message
DescriptionCompiling the following program generates the bogus hint given in the comment in the source on that line:


{$MODE OBJFPC}
{$HINTS ON}
{$OPTIMIZATION OFF}
program main;

function Test(): UTF8String;
begin
   SetLength(Result, 1); // Hint: Function result variable of a managed type does not seem to be initialized
   Result[1] := 'A';
end;

begin
   Writeln(Test());
end.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

Ian Hickson

2020-04-26 04:18

reporter   ~0122433

Sorry, subject line should have been "bogus 'Function result variable of a managed type does not seem to be initialized' message".

Thaddy de Koning

2020-04-26 08:21

reporter   ~0122435

I think it is a duplicatie, but indeed setlength initializes the element(s) to zero if a dynamic array grows.
https://www.freepascal.org/docs-html/rtl/system/setlength.html

Bart Broersma

2020-04-26 10:23

reporter   ~0122438

The compiler basically "sees" Test() as Test(var Result).

Sven Barth

2020-04-26 10:25

manager   ~0122439

The hint/warning is there for a reason:

{$mode objfpc}{$H+}

function Test1: UTF8String;
begin
  Result := 'Foo';
end;

function Test2: UTF8String;
begin
  SetLength(Result, 1);
  Writeln(Result);
end;

var
  s: UTF8String;
begin
  s := Test1;
  s := Test2;
end.


This will print

F

Issue History

Date Modified Username Field Change
2020-04-26 04:17 Ian Hickson New Issue
2020-04-26 04:18 Ian Hickson Note Added: 0122433
2020-04-26 08:21 Thaddy de Koning Note Added: 0122435
2020-04-26 10:23 Bart Broersma Note Added: 0122438
2020-04-26 10:24 Sven Barth Summary bogus 'Warning: Symbol "$assign" is deprecated' message => bogus 'Function result variable of a managed type does not seem to be initialized' message
2020-04-26 10:24 Sven Barth FPCTarget => -
2020-04-26 10:25 Sven Barth Assigned To => Sven Barth
2020-04-26 10:25 Sven Barth Status new => resolved
2020-04-26 10:25 Sven Barth Resolution open => won't fix
2020-04-26 10:25 Sven Barth Note Added: 0122439