View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0012508||FPC||Compiler||public||2008-10-28 10:15||2015-10-06 10:18|
|Reporter||Dmitry Boyarintsev||Assigned To|
|Summary||0012508: no warning for loop variable usage after "for"|
i : integer;
for i := 0 to 5 do
writeln(i); // no note, hint or warning
|Tags||No tags attached.|
|Fixed in Revision|
no difference if variable is global or procedure local
it seems that 2.2.2 compiler version does not report anything too.
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 .
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.
|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|