Alfonso Ruipérez wrote:
{$ extended-pascal} {gpc version 20050331, based on gcc-3.2.3 (mingw special 20030504-1)} program SuccPred (input, output); {ISO 6.7.6.3 (pg. 78 succ(x, k) x shall be of an ordinal-type k shall be of integer-type ... It shall be an error if such a value does not exist. succ(x) Shall be equivalent to succ(x, 1) pred(x) Shall be equivalent to succ(x, -1) }
var b: boolean value false;
begin writeln('succ(b, 2) = ', Succ(b, 2) ); {must be error!} writeln('Pred(b) = ', Pred(b)); {must be error!}
{The next sentence is an error ISO 6.4.2.2 a.1 pg 24 All integral values in the closed interval from -maxint to +maxint shall be values of the integer-type.} {So... pred(-maxint) is not of the integer-type. There must be another out of range error!} writeln('pred(-maxint) = ', pred(-maxint)); {With the next sentence the compiler say 'arithmetical overflow' perhaps should say 'out of range'} writeln('succ( maxchar ) = ', succ( maxchar ) );
end.
GPC doesn't implement all checks yet. This one would belong to "overflow" checking which has yet to be implemented, for the most part. A few special cases are implemented already, such as some overflows that can be detected at compile-time -- your last example is one such case, and that's why it says overflow.
The difference between range and overflow checking (in our terminology): Range check error means the value belongs to an ordinal base type, but does not fit the given range. Overflow checking means it's out of the base type. Therefore, overflow checking is somewhat more difficult to do, and in general also more expensive at runtime -- for range checking we can first compute the value in the base type, then compare; for overflow checking we generally have to do checks before the operation. That's why we'll make it a different option, as some programmers may not want the greater overhead of overflow checking.
As for standard compliance: Yes, it's an error, but errors may be left undetected (3.2). So it's not actually a deviation (if documented). There are other errors, such as accessing undefined values, that may not be checked for any time soon (or ever) ...
So if you rely on overflow checking, I'm afraid, you're out of luck at the moment. You can wait some time until we might implement it, or could try to help implementing it (if you dare working on the compiler internals) ...
Frank