On Jun 11, 2007, at 1:13 AM, Adriaan van Os wrote:
Any comment on http://www.freepascal.org/mantis/view.php?id=9053 and Daniël Mantione's note ?
There is no error in GPC's handling of the program UnknownLocalSymbol. For easy reference, the program is:
program UnknownLocalSymbol;
procedure p; label 10; begin if False then begin 10: Exit end; goto 10 end;
begin end.
The program doesn't meet ISO Pascal's requirements for goto statements. GPC correctly detects the error and issues a correct error message.
In regards to Daniël Mantione's note:
"Allthough GPC handles it more nicely, I'd say both compilers are in error; since the exit statement is reachable via the goto, the compiler is not allowed to optimize the if-statement away."
Daniël is mistaken that the exit statement is reachable via the goto in a legal ISO Pascal program. The label prefixing statement "10: Exit" does not satisfy any of the goto statement containing requirements of ISO 10206, paragraph 6.9.1 general requirements for labels and goto statements:
"A label, if any, of a statement S shall be designated as prefixing S. The label shall be permitted to occur in a goto-statement G (see 6.9.2.4) if and only if any of the following three conditions is satisfied.
a) S contains G.
b) S is a statement of a statement-sequence containing G.
c) S is a statement of the statement-sequence of the compound- statement of the statement-part of a block containing G.
statement = [ label ':' ] ( simple-statement j structured- statement ) .
NOTE --- 2 A goto-statement within a block may refer to a label in an enclosing block, provided that the label prefixes a statement at the outermost level of nesting of the block. "
It appears that Daniël is also erroneously assuming the reason for GPC's error message is because the if statement was optimized away. That isn't the reason for GPC's error message. The reason is because the label "10" isn't permitted to occur in the goto statement per ISO requirements.
Since FPC makes no claims for ISO Pascal requirements compliance, the FPC compiler may not enforce ISO label and goto statement requirements so what is or isn't legal with FPC depends upon what the FPC compiler folks have defined the requirements to be. As a general observation I'll note that transferring control into a nested statement can result in ill program behavior which is why ISO PAscal prohibits it.
Gale Paeper gpaeper@empirenet.com