Browse Source

* forbid "nil +/- ordinal" expressions (Delphi-compatible, and the
expression is meaningless since nil is not a valid address)

git-svn-id: trunk@13205 -

Jonas Maebe 16 năm trước cách đây
mục cha
commit
7e908cb1e3
3 tập tin đã thay đổi với 11 bổ sung1 xóa
  1. 1 0
      .gitattributes
  2. 3 1
      compiler/nadd.pas
  3. 7 0
      tests/tbf/tb0216.pp

+ 1 - 0
.gitattributes

@@ -6703,6 +6703,7 @@ tests/tbf/tb0215b.pp svneol=native#text/plain
 tests/tbf/tb0215c.pp svneol=native#text/plain
 tests/tbf/tb0215d.pp svneol=native#text/plain
 tests/tbf/tb0215e.pp svneol=native#text/plain
+tests/tbf/tb0216.pp svneol=native#text/plain
 tests/tbf/ub0115.pp svneol=native#text/plain
 tests/tbf/ub0149.pp svneol=native#text/plain
 tests/tbf/ub0158a.pp svneol=native#text/plain

+ 3 - 1
compiler/nadd.pas

@@ -228,7 +228,7 @@ implementation
              allowenumop(nodetype))
             ) or
             (
-             (lt in [pointerconstn,niln]) and
+             (lt = pointerconstn) and
              is_constintnode(right) and
              (nodetype in [addn,subn])
             ) or
@@ -1726,6 +1726,8 @@ implementation
              inserttypeconv(right,sinttype);
              if nodetype in [addn,subn] then
                begin
+                 if (lt=niln) then
+                   CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),'NIL',rd.typename);
                  if not(cs_extsyntax in current_settings.moduleswitches) or
                     (not(is_pchar(ld)) and not(m_add_pointer in current_settings.modeswitches)) then
                    CGMessage3(type_e_operator_not_supported_for_types,node2opstr(nodetype),ld.typename,rd.typename);

+ 7 - 0
tests/tbf/tb0216.pp

@@ -0,0 +1,7 @@
+{ %fail }
+
+var
+  p: pointer;
+begin
+  p:=nil+1;
+end.