<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body smarttemplateinserted="true">
<div id="smartTemplate4-template">Hi,<br>
<br>
<p>
<blockquote type="cite">
<p style="padding:0 0 0 0; margin:0 0 0 0;">even if there's
closed issue <a class="moz-txt-link-freetext" href="https://bugs.freepascal.org/view.php?id=34169">https://bugs.freepascal.org/view.php?id=34169</a> 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>
</blockquote>
</p>
<p><br>
</p>
<p>seriously that is such a bullshit warning.<br>
</p>
SetLength is called to initialize the variable, of course the
variable is not initialized before. If it was initialized, we
might not even need to call SetLength<br>
</div>
<div><br>
Cheers,<br>
Benito </div>
<br>
<div class="moz-cite-prefix">Am 04.09.18 um 15:53 schrieb Vojtěch
Čihák:<br>
</div>
<blockquote type="cite" cite="mid:20180904155303.D5DEA9A2@atlas.cz">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<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 <a class="moz-txt-link-freetext" href="https://bugs.freepascal.org/view.php?id=34169">https://bugs.freepascal.org/view.php?id=34169</a> 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>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-pascal maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a></pre>
</blockquote>
</body>
</html>