Przeglądaj źródła

* fixed array[..] of char <op> pchar: wrong type was determined for non op<>+ returned

git-svn-id: trunk@1107 -
florian 20 lat temu
rodzic
commit
fa1575aeab
3 zmienionych plików z 29 dodań i 12 usunięć
  1. 1 0
      .gitattributes
  2. 16 12
      compiler/nadd.pas
  3. 12 0
      tests/tbs/tb0494.pp

+ 1 - 0
.gitattributes

@@ -4971,6 +4971,7 @@ tests/tbs/tb0490.pp svneol=native#text/plain
 tests/tbs/tb0491.pp svneol=native#text/plain
 tests/tbs/tb0492.pp svneol=native#text/plain
 tests/tbs/tb0493.pp svneol=native#text/plain
+tests/tbs/tb0494.pp -text
 tests/tbs/ub0060.pp svneol=native#text/plain
 tests/tbs/ub0069.pp svneol=native#text/plain
 tests/tbs/ub0119.pp svneol=native#text/plain

+ 16 - 12
compiler/nadd.pas

@@ -1085,20 +1085,24 @@ implementation
                 inserttypeconv(right,left.resulttype);
              end;
           end
-
-         { compare pchar to char arrays by addresses like BP/Delphi }
-         else if ((is_pchar(ld) or (lt=niln)) and is_chararray(rd)) or
-                 ((is_pchar(rd) or (rt=niln)) and is_chararray(ld)) then
-           begin
-             if is_chararray(rd) then
-              inserttypeconv(right,charpointertype)
-             else
-              inserttypeconv(left,charpointertype);
-           end
-
          { pointer comparision and subtraction }
-         else if (rd.deftype=pointerdef) and (ld.deftype=pointerdef) then
+         else if ((rd.deftype=pointerdef) and (ld.deftype=pointerdef)) or
+                 { compare pchar to char arrays by addresses like BP/Delphi }
+                 ((is_pchar(ld) or (lt=niln)) and is_chararray(rd)) or
+                 ((is_pchar(rd) or (rt=niln)) and is_chararray(ld)) then
           begin
+            { convert char array to pointer }
+            if is_chararray(rd) then
+              begin
+                inserttypeconv(right,charpointertype);
+                rd:=right.resulttype.def;
+              end
+            else if is_chararray(ld) then
+              begin
+                inserttypeconv(left,charpointertype);
+                ld:=left.resulttype.def;
+              end;
+
             case nodetype of
                equaln,unequaln :
                  begin

+ 12 - 0
tests/tbs/tb0494.pp

@@ -0,0 +1,12 @@
+{ the test checks only if the syntax is possible }
+var
+  ca : array[0..1000] of char;
+  p1 : pchar;
+
+begin
+  p1:=nil;
+  if (ca-p1)=0 then
+    halt(1); 
+  p1:=ca;
+end.
+