Browse Source

* Revert changes to tarray15.pp
* Modify treadonlydata.pp to not use dynamic array.
+ Add test treadonlydata2.pp that should fail at compile time.

git-svn-id: trunk@42752 -

pierre 6 years ago
parent
commit
e45ad64d41
4 changed files with 82 additions and 13 deletions
  1. 1 0
      .gitattributes
  2. 12 0
      tests/test/tarray15.pp
  3. 43 13
      tests/test/treadonlydata.pp
  4. 26 0
      tests/test/treadonlydata2.pp

+ 1 - 0
.gitattributes

@@ -15067,6 +15067,7 @@ 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/treadonlydata2.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

+ 12 - 0
tests/test/tarray15.pp

@@ -1,5 +1,10 @@
 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 }
@@ -79,6 +84,13 @@ begin
     Halt(17);
   if not specialize CheckArray<LongInt>(rc1, [1, 2, 3]) then
     Halt(18);
+{$ifdef target_supports_rodata}
+  try
+    rc1[1] := 42;
+    Halt(19);
+  except
+  end;
+{$endif}
   if not specialize CheckArray<LongInt>(wc1, [1, 2, 3]) then
     Halt(20);
   wc1[1] := 42;

+ 43 - 13
tests/test/treadonlydata.pp

@@ -14,35 +14,65 @@ uses
 {$push}
 {$J-}
 const
-  rc1: array of LongInt = (1, 2, 3);
+  rc: LongInt = 5;
+  rc1: array [0..2] of LongInt = (1, 2, 3);
 {$J+}
 const
-  wc1: array of LongInt = (1, 2, 3);
+  wc: LongInt = 78;
+  wc1: array [0..2] of LongInt = (1, 2, 3);
+  has_errors : boolean = false;
 {$pop}
-
+var
+  p : plongint;
 
 begin
 {$ifdef target_supports_rodata}
   try
-    rc1[1] := 42;
-    writeln('Error: Trying to write read-only data did not generate an exception');
-    Halt(1);
+    p := @rc;
+    p^ := 42;
+    writeln('Error: Trying to write a read-only longint constant did not generate an exception');
+    has_errors:=true;
   except
-    writeln('Trying to write read-only data generated exception');
+    writeln('OK: Trying to write read-only data generated exception');
+  end;
+  try
+    p := @rc1[1];
+    p^ := 42;
+    writeln('Error: Trying to write a read-only longint array data element did not generate an exception');
+    has_errors:=true;
+  except
+    writeln('OK: 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');
+    p := @rc;
+    p^ := 42;
+    writeln('Trying to write a read-only longint constant did not generate an exception, as expected');
+  except
+    writeln('Trying to write a read-only longint constant generated exception, while system is supposed not to support this');
+    has_errors:=true;
+  end;
+  try
+    p := @rc1[1];
+    p^ := 42;
+    writeln('Trying to write a read-only longint array data element 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);
+    writeln('Trying to write a read-only longint array data element generated exception, while system is supposed not to support this');
+    has_errors:=true;
   end;
 {$endif}
+  try
+    wc := 42;
+  except
+    writeln('Error: Trying to write normal longint initialized "const" generated exception');
+    has_errors:=true;
+  end;
   try
     wc1[1] := 42;
   except
-    writeln('Error: Trying to write normal data generated exception');
-    halt(3);
+    writeln('Error: Trying to write normal array data element generated exception');
+    has_errors:=true;
   end;
+  if has_errors then
+    halt(1);
 end.

+ 26 - 0
tests/test/treadonlydata2.pp

@@ -0,0 +1,26 @@
+{%FAIL }
+
+program treadonlydata2;
+
+{$if defined(msdos) or defined(hasamiga) or defined(atari) or defined(palmos)}
+  {$define target_does_not_support_rodata}
+{$ekse}
+  {$define target_supports_rodata}
+{$endif}
+
+{$mode  objfpc}
+{$J-}
+const
+  c = 89;
+  rc: LongInt = 5;
+var
+  p : pbyte;
+
+begin
+{$ifndef target_does_not_support_rodata}
+  rc := 42;
+{$else}
+  { dummy code to also get a compile time error }
+  p:=@c;
+{$endif}
+end.