Allow unsigned long values greater than 2^31 to be used as the second operand to % in constant expressions.

The following is an example that would give a compile error before this patch:

int main(void)
{
    unsigned long i = 1 % 3000000000;
}

The remainder operation still does not work properly for signed types when either operand is negative. It gives either errors or incorrect values in various cases, both when evaluated at compile time and run time. Fully addressing this (including the run-time cases) would require library updates.
This commit is contained in:
Stephen Heumann 2016-12-18 23:15:15 -06:00
parent f4ad0fab80
commit b6b2121a9e

View File

@ -1100,10 +1100,11 @@ var
op1 := op1 div op2;
end;
percentch : begin {%}
if op2 <= 0 then begin
Error(109);
op2 := 1;
end; {if}
if op2 <= 0 then {FIXME: support negative values}
if (op2 = 0) or (not unsigned) then begin
Error(109);
op2 := 1;
end; {if}
if unsigned then
op1 := umod(op1,op2)
else