Peter N Lewis wrote:
Is a zero length slice a legitimate structure?
Ie
var s, t: String(10); begin if EQ( s[1..0], t[1..0] ) then begin WriteLn( 'TRUE' ); end; end.
Should that work?
No:
: substringÂvariable = stringÂvariable : `[' indexÂexpression `..' indexÂexpression `]' . : : The indexÂexpressions in a substringÂvariable shall possess the : integerÂtype. It shall be an error if the stringÂvariable of the : substringÂvariable is undefined, or if the value of an indexÂexpression in a : substringÂvariable is less than 1 or greater than the length of the value of : the stringÂvariable of the substringÂvariable, or if the value of the first : indexÂexpression is greater than the value of the second indexÂexpression.
Currently it gives
testpas.pas:6: size of array is too large
Fixed in the next release. (peter2*.pas)
however, if the 0 is changed to a runtime variable:
var s, t: String(10); n: Integer; begin n := 0; if EQ( s[1..n], t[1..n] ) then begin WriteLn( 'TRUE' ); end; end.
Then it returns TRUE (as expected, sort of).
Similarly for s := t[1..0]; etc.
So, is it legitimate or not? If it is, the compile error is a bug. If not, then there seems to be a missing runtime range check error (or do I have to enable that)?
Missing runtime range checks are one of the most well-known issues of GPC (even if not strictly a bug, as long as it's documented).
Frank