An ordinal type that does not include the number 1 will get warnings when used with Inc/Dec/Succ/Pred
Summary
A subrange type that does not include the number 1, for example 10..20, will get range check warnings on the implicit "1" constant that Inc, Dec, Succ, and Pred use.
Steps to reproduce
Compile this:
{$MODE OBJFPC}
type
TTest = 10..20;
var
A: TTest;
begin
A := 10;
Inc(A);
Writeln(Succ(A)); // 12
Writeln(Pred(A)); // 10
Dec(A);
end.
You will get four warnings:
test.pas(11,4) Warning: Range check error while evaluating constants (1 must be between 10 and 20)
test.pas(12,19) Warning: Range check error while evaluating constants (1 must be between 10 and 20)
test.pas(13,19) Warning: Range check error while evaluating constants (1 must be between 10 and 20)
test.pas(14,4) Warning: Range check error while evaluating constants (1 must be between 10 and 20)
Amusingly, this code will not get a warning:
A := A + 1;
System Information
- Operating system: Linux
- Processor architecture: x86-64
- Compiler version: trunk compiled on 2025/07/03
- Device: Computer