Hello,
FPC (v3.0.4) does not catch all attempts to write to non-writeable constants even when they are evident. Consider the test program below:
{$APPTYPE CONSOLE}
{$TYPEDADDRESS ON}
{$LONGSTRINGS OFF}
{$WRITEABLECONST OFF}
{ --------------------------------------------------------------------------- }
program _writeableconst;
const
ArrayConst : array[0..1] of
record
t : pchar;
l : DWORD
end =
(
(t: 'some text'; l: 0),
(t: 'more text'; l: 0)
);
v : DWORD = 0;
var
i : integer;
begin
for i := low(ArrayConst) to high(ArrayConst) do
begin
with ArrayConst[i] do
begin
{ assign to a non writeable constant, yet NO compiler error emitted }
{ BUT, you get an access violation at runtime (as there should be) }
l := i + 10; { set to any value }
end;
end;
{ this statement causes a compile time error - as it should }
v := 1; { compile error - as expected }
end.
The compiler rightfully complains about the statement in line 42 about the attempt to write to a non-writeable constant but, says _nothing_ about line 36 which, isn't really different than line 42.
If line 42 is commented out, the program compiles and when run causes an access violation because the constant is in a read-only segment.
Given that I've only tested this using FPC v3.0.4, I have not filed a bug since it won't be corrected in that old version but, it's probably worth checking how the newer FPC versions behave in that case.
HTH.