Browse Source

* allow type casted pointer constants being used as arrays which address can be takes, resolves #41177

florian 4 tháng trước cách đây
mục cha
commit
36e9e39bca
2 tập tin đã thay đổi với 21 bổ sung1 xóa
  1. 9 1
      compiler/htypechk.pas
  2. 12 0
      tests/webtbs/tw41177.pp

+ 9 - 1
compiler/htypechk.pas

@@ -1750,7 +1750,15 @@ implementation
              niln,
              pointerconstn :
                begin
-                if report_errors then
+                 { this is an implicit dereference, so it is valid for assign }
+                 if hp.resultdef.typ=arraydef then
+                   begin
+                     valid_for_assign:=true;
+                     mayberesettypeconvs;
+                     exit;
+                   end;
+
+                 if report_errors then
                    CGMessagePos(hp.fileinfo,type_e_no_assign_to_addr);
                  mayberesettypeconvs;
                  exit;

+ 12 - 0
tests/webtbs/tw41177.pp

@@ -0,0 +1,12 @@
+program test;
+{$pointermath on}
+
+type
+  PRec = ^TRec;
+  TRec = record
+  end;
+
+begin
+  argv:=@PRec(0)[0];   // OK
+  argv:=@PRec(nil)[0]; // NotOK - "Can't assign values to an address"
+end.