<p style="padding:0 0 0 0; margin:0 0 0 0;">Hello,</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">even if there's closed issue https://bugs.freepascal.org/view.php?id=34169 I would like to ask if it can be reconsidered.</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">The subject is that SetLength now gives warning: Variable "dynamic array" of a managed type does not seem to be initialized</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">in 3.3.1 and 3.1.1 while it doesn't give any warning in stable 3.0.4</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">As a solution is recommended do declaration: var arr: array of widechar = ();</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">But it means that initialization is in fact done twice. See assembler of following code:</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">procedure TForm1.Button1Click(Sender: TObject);</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">var DA: array of widechar = ();</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">begin</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> SetLength(DA, 10);</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> writeln(DA[0]);</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">end; </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">unit1.pas:30 var DA: array of widechar = ();</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">00000000004696C9 488d1538536600 lea 0x665338(%rip),%rdx # 0xacea08 <RTTI_$UNIT1_$$_def00000138></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">00000000004696D0 488b3529536600 mov 0x665329(%rip),%rsi # 0xacea00 <TC_$UNIT1$_$TFORM1_$_BUTTON1CLICK$TOBJECT_$$_defaultDA></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">00000000004696D7 4889e7 mov %rsp,%rdi</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">00000000004696DA e8d199fcff callq 0x4330b0 <fpc_dynarray_assign></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">unit1.pas:32 SetLength(DA, 10);</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">00000000004696DF 48c74424680a000000 movq $0xa,0x68(%rsp)</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">00000000004696E8 488d3519536600 lea 0x665319(%rip),%rsi # 0xacea08 <RTTI_$UNIT1_$$_def00000138></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">00000000004696EF 488d4c2468 lea 0x68(%rsp),%rcx</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">00000000004696F4 4889e7 mov %rsp,%rdi</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">00000000004696F7 ba01000000 mov $0x1,%edx</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">00000000004696FC e8df99fcff callq 0x4330e0 <fpc_dynarray_setlength></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">unit1.pas:33 writeln(DA[0]);</p>
<div>To avoid warning we now need four extra instructions incl. call to fpc_array_assign, which is obviously redundant.</div>
<div>As an explanation is written: Setlength uses a var parameter. This is no different from other cases of var parameter usage.</div>
<div>I disaggre here, because SetLength is not an usual procedure, it is fundamental part of compiler. Therefore it deserves some exception.</div>
<div>That's why I ask for reconsidering and make it behave like in 3.0.4 or change declaration from "var" to "out" as it is done in getmem().</div>
<div>Thanks, Vojtěch.</div>
<div> </div>