View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0018234 | FPC | Compiler | public | 2010-12-16 21:18 | 2010-12-20 16:17 |
Reporter | Andrzej Borucki | Assigned To | Jonas Maebe | ||
Priority | normal | Severity | feature | Reproducibility | always |
Status | resolved | Resolution | duplicate | ||
Platform | x86 | OS | WindowsXP | ||
Product Version | 2.4.2 | ||||
Summary | 0018234: No warning if loop variable is used after for-loop without "break" | ||||
Description | Value after for loop sometimes is used to distinguish if was break. In Delphi value is next to last bound, in FreePascal value is last bound. If FreePascal solution has more sense, should be Delphi solution for {$MODE Delphi} or warning: value after loop may be undefined | ||||
Steps To Reproduce | {$MODE Delphi} var i: integer; begin for i:=0 to 9 do; writeln(i);{delphi say 10, FreePascal say 9} for i:=0 to 9 do if i=9 then break; writeln(i);{delphi say 9, FreePascal say 9} end. | ||||
Tags | No tags attached. | ||||
Fixed in Revision | |||||
FPCOldBugId | 0 | ||||
FPCTarget | |||||
Attached Files |
|
duplicate of | 0012508 | new | no warning for loop variable usage after "for" |
|
See also http://www.hu.freepascal.org/lists/fpc-pascal/2007-March/013428.html |
|
The result is also undefined in Delphi (Kylix) if there is no "break": $ cat tt3.pp var i: integer; begin for i:=0 to 9 do; writeln(i);{delphi say 10, FreePascal say 9} for i:=0 to 9 do if i=9 then break; writeln(i);{delphi say 9, FreePascal say 9} end. $ dcc tt3.pp Borland Delphi for Linux Version 14.5 Copyright (c) 1983,2002 Borland Software Corporation tt3.pp(4) Warning: FOR-Loop variable 'i' may be undefined after loop tt3.pp(8) 9 lines, 0.00 seconds, 22172 bytes code, 3088 bytes data. Adding a warning is possible, but it requires several changes (the simple "solution" would result in wrong warnings that the variable is not used at all in the function in case it's not used anymore after the loop; and it also needs different handling depending on whether there's a "break" inside the loop, as demonstrated above). |
|
Since the value may be undefined, if would better to cause not only warning but even error, if you use variable after loop (as well as the use of any local variable without initialization) ? |
|
> would better to cause not only warning but even error There are some safety-critical languages that do this, but Pascal is not one of them. Furthermore, the current analysis by the compiler of which variables are initialised and which are not is far from perfect, so it would also cause problems with compiling valid code. |
Date Modified | Username | Field | Change |
---|---|---|---|
2010-12-16 21:18 | Andrzej Borucki | New Issue | |
2010-12-16 22:07 | Vincent Snijders | Note Added: 0044274 | |
2010-12-16 23:36 | Jonas Maebe | Note Added: 0044276 | |
2010-12-16 23:37 | Jonas Maebe | FPCOldBugId | => 0 |
2010-12-16 23:37 | Jonas Maebe | Summary | Value after for loop in Delphi mode => No warning if loop variable is used after for-loop without "break" |
2010-12-18 07:30 | Andrzej Borucki | Note Added: 0044317 | |
2010-12-18 20:19 | Jonas Maebe | Note Added: 0044354 | |
2010-12-20 16:17 | Jonas Maebe | Relationship added | duplicate of 0012508 |
2010-12-20 16:17 | Jonas Maebe | Duplicate ID | 0 => 12508 |
2010-12-20 16:17 | Jonas Maebe | Status | new => resolved |
2010-12-20 16:17 | Jonas Maebe | Resolution | open => duplicate |
2010-12-20 16:17 | Jonas Maebe | Assigned To | => Jonas Maebe |