View Issue Details

IDProjectCategoryView StatusLast Update
0012508FPCCompilerpublic2015-10-06 10:18
ReporterDmitry Boyarintsev Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Product Version2.3.1 
Summary0012508: no warning for loop variable usage after "for"
Descriptionvar
  i : integer;
begin
  for i := 0 to 5 do
    writeln(i);
  writeln(i); // no note, hint or warning
end.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Relationships

has duplicate 0018234 resolvedJonas Maebe No warning if loop variable is used after for-loop without "break" 

Activities

Dmitry Boyarintsev

2008-10-28 10:52

developer   ~0022987

Last edited: 2008-10-28 11:16

no difference if variable is global or procedure local

it seems that 2.2.2 compiler version does not report anything too.

Dmitry Boyarintsev

2015-10-05 17:28

developer   ~0086256

Last edited: 2015-10-05 17:28

View 2 revisions

Break or Goto make the iterator a valid variable.

ISO/IEC 7185 :1990(E) says in section 6.8 .3.9 For-statements

After a for-statement is executed, other than being left by a goto-statement, the control-variable shall be undefined .

Discussion: http://lists.freepascal.org/pipermail/fpc-pascal/2015-October/045433.html

Thaddy de Koning

2015-10-06 10:18

reporter   ~0086269

That is correct and works correct, also in Delphi.
The problem here is that the compiler or compilers in general are known to optimize certain "for" loops by down counting instead of up counting. So depending on the level of optimization the index is really not definable except for exiting the for loop prematurely in which case the correct index should be returned.

This may or may not be implemented in FPC already, and these two states are deterministically the only two states I have seen in multiple compilers for multiple languages.

Issue History

Date Modified Username Field Change
2008-10-28 10:15 Dmitry Boyarintsev New Issue
2008-10-28 10:52 Dmitry Boyarintsev Note Added: 0022987
2008-10-28 11:16 Dmitry Boyarintsev Note Edited: 0022987
2010-12-20 16:17 Jonas Maebe Relationship added has duplicate 0018234
2015-10-05 17:28 Dmitry Boyarintsev Note Added: 0086256
2015-10-05 17:28 Dmitry Boyarintsev Note Edited: 0086256 View Revisions
2015-10-06 10:18 Thaddy de Koning Note Added: 0086269