I would like to define HTML response status code numbers as a type but disallow arithmetic operators because it wouldn't make sense for them.
type Status_Code is range 100 .. 599;
function "+" (Left, Right : Status_Code) return Status_Code is
begin
pragma Assert (1 = -1);
return Left + Right;
end;
The code snippet above on GNAT will give an error saying assertion will fail on runtime, but that is false when I add two of the numbers together. Is there a way to force a compiler error or at least a warning when arithmetic attempted on a type like this?
You can declare it as abstract:
function "+" (Left, Right : Status_Code) return Status_Code is abstract;