The following was initially discovered by Gale Paeper.
[g5:~/gpc/testgpc/adriaan] adriaan% cat rangecheck1.p
program rangecheck1; var i: 1..5; begin i:= 5; {$local R-} i:= i+1; {$endlocal} i:= 4; i:= i+2; writeln( 'i = ', i); end.
[g5:~/gpc/testgpc/adriaan] adriaan% gpc41 rangecheck1.p --range-checking [g5:~/gpc/testgpc/adriaan] adriaan% ./a.out i = 6
[g5:~/gpc/testgpc/adriaan] adriaan% cat rangecheck2.p
{$R+} program rangecheck2; var i: 1..5; begin i:= 5; {$local R-} i:= i+1; {$endlocal} i:= 4; i:= i+2; writeln( 'i = ', i); end. [g5:~/gpc/testgpc/adriaan] adriaan% gpc41 rangecheck2.p --range-checking [g5:~/gpc/testgpc/adriaan] adriaan% ./a.out ./a.out: value out of range (error #300 at 2487)
[g5:~/gpc/testgpc/adriaan] adriaan% cat rangecheck3.p
{$R+} program rangecheck3; var i: 1..5; begin i:= 5; {$local R-} i:= i+1; {$endlocal} writeln( 'i = ', i); end. [g5:~/gpc/testgpc/adriaan] adriaan% gpc41 rangecheck3.p --range-checking [g5:~/gpc/testgpc/adriaan] adriaan% ./a.out i = 6
[g5:~/gpc/testgpc/adriaan] adriaan% cat rangecheck4.p
{$R+} program rangecheck4; var i: 1..5; begin i:= 4; i:= i+2; writeln( 'i = ', i); end. [g5:~/gpc/testgpc/adriaan] adriaan% gpc41 rangecheck4.p --range-checking [g5:~/gpc/testgpc/adriaan] adriaan% ./a.out ./a.out: value out of range (error #300 at 2477)
[g5:~/gpc/testgpc/adriaan] adriaan% gpc41 -v Using built-in specs. Configured with: ../gcc-4.1.0/configure --enable-languages=c,pascal --enable-threads=posix --target=powerpc-apple-darwin8 --host=powerpc-apple-darwin8 --build=powerpc-apple-darwin8 --prefix=/Developer/Pascal/gpc410d1 Thread model: posix gpc version 20060325, based on gcc-4.1.0
In other words, {$local R-} disables range-checking for the rest of the file when using --range-checking as a command-line option, not when using {$R+}. I can hardly imagine this is intended behaviour.
Regards,
Adriaan van Os
Adriaan van Os wrote:
The following was initially discovered by Gale Paeper.
[...]
In other words, {$local R-} disables range-checking for the rest of the file when using --range-checking as a command-line option, not when using {$R+}. I can hardly imagine this is intended behaviour.
Of course not. It's a bug, and it's related to the fact that $R+ doesn't exactly correspond to --range-checking, but to --range-and-object-checking which in turn corresponds to --range-checking plus --object-checking. This is because unfortunately BP coupled these two unrelated checks to the same option (as they had only short options and there are only 26 letters ...)
The following patch shold fix the problems reported (gale12[a-h].pas). However, the problem in somewhat deeper, which shows when mixing both kinds (only range,, and range + objects) such as {$R-,range-checking}, as shown in gale12i.pas (added by myself). With some planned preprocessor changes (make $local work on the internal options structure directly, rather than on textual options, as was required with the external preprocessor), this will be fixed for free, so I won't spend time on a work-around now ...
Frank