Re: for-loops and subrange types

Jonas Maebe <[email protected]>
Newsgroups gmane.comp.compilers.gpc
Message-ID <[email protected]>
On 26 Apr 2013, at 22:22, Waldek Hebisch wrote:

>> Hi,
>> 
>> Can anyone here offer some insights regarding the standard conformance of the test program submitted at http://bugs.freepascal.org/view.php?id=24318 ? (range.p)
>> 
>> Both FPC and GPC cause the program to abort with a range check error, while the submitter is of the opinion that the for-loop should merely short-circuit and never executed instead.
>> 
> 
> AFAICS he is right.  ISO-10206 clause 6.9.3.9.2 says:
> 
> : The initial-value and the final-value of a sequence-iteration
> : of an iteration-clause of a for-statement shall be of a type
> : compatible with the type of control-variable of the for-statement.
> : The initial-value and the final-value shall be
> : assignment-compatible with the type possesed by the
> : control-variable if the statement of the for-statement
> : is executed.
> 
> Compatible type for integer subrange means that any integer
> value is OK.  Assignment-compatible means that values must
> be in range, but is only required when loop body is
> actually executed.

The for-statement includes the initial-value assignment to the control-variable and the comparison of the control-variable with the final-value. That part of the for-statement is executed any time the control flow of the program reaches the for-loop. That's why I believe that the assignment-compatibility rule applies.


Jonas

_______________________________________________
Gpc mailing list
[email protected]
https://www.g-n-u.de/mailman/listinfo/gpc
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.