<HTML>
<p><style> BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; }</style>That looks sensible. Sorry to waste your time on this. I'm glad it states the for-loop variable will be left undefined - that's good enough documentation for me.</p><p>I wouldn't call it a quick fix... more of fixing an oversight, since I can see the trick of using Result as the for-counter being very easily overlooked. Of course, the perfect fix is only counting "exitn" if the for-loop counter is Result. One to test for later.</p><p>Gareth aka. Kit<br>
<br>
<br>
<br>
<span style="font-weight: bold;">On Fri 18/05/18 14:40 , Martok listbox@martoks-place.de sent:<br>
</span></p><blockquote style="padding-right: 0px; padding-left: 5px; margin-right: 0px; margin-left: 5px; border-left-color: rgb(245, 245, 245); border-left-width: 2px; border-left-style: solid;"><span style="color: rgb(102, 102, 102);">> Citation: "If the loop was terminated prematurely with an exception or a
</span><br>
<span style="color: rgb(102, 102, 102);">> break statement, the loop variable retains the value it had when the
</span><br>
<span style="color: rgb(102, 102, 102);">> loop was exited."
</span><br>
As a quick fix, not unrolling loops left with exit at least fixes this specific
<br>
situation. This still leaves exceptions raised, but IIRC the handlers don't
<br>
restore context anyways, we might be okay?
<br>
<br>
diff --git a/compiler/optloop.pas b/compiler/optloop.pas
<br>
index 46039ffc5a..dc714ea2cc 100644
<br>
--- a/compiler/optloop.pas
<br>
+++ b/compiler/optloop.pas
<br>
@@ -76,7 +76,7 @@ unit optloop;
<br>
<br>
function checkbreakcontinue(var n:tnode; arg: pointer): foreachnoderesult;
<br>
begin
<br>
- if n.nodetype in [breakn,continuen] then
<br>
+ if n.nodetype in [breakn,continuen,exitn] then
<br>
result:=fen_norecurse_true
<br>
else
<br>
result:=fen_false;
<br>
<br>
I'll be running this on today's snapshot, see if anything else remains.
<br>
<br>
--
<br>
Regards,
<br>
Martok
<br>
<br>
<br>
_______________________________________________
<br>
fpc-devel maillist - <a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<br>
<a href="<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>" target="_blank"><span style="color: red;">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</span></a>
<br>
<br>
<br>
</blockquote></HTML>