Is this intended?
program test;
{$mode objfpc}{$j-}
const
Items: array of Integer = (1, 2, 3);
var
I: Integer;
begin
for I := 0 to High(Items) do begin
Inc(Items[I]);
WriteLn(Items[I]);
end;
end.
It compiles and runs for at least the current Linux64 compiler.
While the compiler could be improved to reject the
Inc on a typed dynamic array constant right away the effect on the current code at
runtime is platform dependent, because not on every platform the data will be put into a readonly section. For example on Windows (no matter if 32- or 64-bit) your code will result in a runtime error. On Linux however the compiler currently does not support putting typed constants into a readonly section due to requirements for relocations. And other platforms (like DOS) simply don't support that at all...
But you could report a bug for the compiler not rejecting the
Inc at compile time. This is likely a remnant of the fact that typed dynamic array constants were only introduced in FPC 3.2.0.