diff --git a/.gitattributes b/.gitattributes index caad0ce74b..1088c9de73 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15065,6 +15065,7 @@ tests/test/trange3.pp svneol=native#text/plain tests/test/trange4.pp svneol=native#text/plain tests/test/trange5.pp svneol=native#text/plain tests/test/trangeob.pp svneol=native#text/plain +tests/test/treadonlydata.pp svneol=native#text/pascal tests/test/trecreg.pp svneol=native#text/plain tests/test/trecreg2.pp svneol=native#text/plain tests/test/trecreg3.pp svneol=native#text/plain diff --git a/tests/test/tarray15.pp b/tests/test/tarray15.pp index 9f2c1c64e0..1a4edbed1d 100644 --- a/tests/test/tarray15.pp +++ b/tests/test/tarray15.pp @@ -1,10 +1,5 @@ program tarray15; -{$define target_supports_rodata} -{$if defined(msdos) or defined(hasamiga) or defined(atari) or defined(palmos)} -{$undef target_supports_rodata} -{$endif} - {$mode objfpc} { needed for "except" to work } @@ -84,13 +79,6 @@ begin Halt(17); if not specialize CheckArray(rc1, [1, 2, 3]) then Halt(18); -{$ifdef target_supports_rodata} - try - rc1[1] := 42; - Halt(19); - except - end; -{$endif} if not specialize CheckArray(wc1, [1, 2, 3]) then Halt(20); wc1[1] := 42; diff --git a/tests/test/treadonlydata.pp b/tests/test/treadonlydata.pp new file mode 100644 index 0000000000..8f371c4168 --- /dev/null +++ b/tests/test/treadonlydata.pp @@ -0,0 +1,48 @@ +program treadonlydata; + +{$define target_supports_rodata} +{$if defined(msdos) or defined(hasamiga) or defined(atari) or defined(palmos)} +{$undef target_supports_rodata} +{$endif} + +{$mode objfpc} + +{ needed for "except" to work } +uses + SysUtils; + +{$push} +{$J-} +const + rc1: array of LongInt = (1, 2, 3); +{$J+} +const + wc1: array of LongInt = (1, 2, 3); +{$pop} + + +begin +{$ifdef target_supports_rodata} + try + rc1[1] := 42; + writeln('Error: Trying to write read-only data did not generate an exception'); + Halt(1); + except + writeln('Trying to write read-only data generated exception'); + end; +{$else} + try + rc1[1] := 42; + writeln('Trying to write read-only data did not generate an exception, as expected'); + except + writeln('Trying to write read-only data generated exception, while system is supposed not to support this'); + halt(2); + end; +{$endif} + try + wc1[1] := 42; + except + writeln('Error: Trying to write normal data generated exception'); + halt(3); + end; +end.