Browse Source

* some typeconvs don't allow assignment or passing to var para

peter 21 years ago
parent
commit
a9df763770
2 changed files with 39 additions and 2 deletions
  1. 11 1
      compiler/htypechk.pas
  2. 28 1
      compiler/ncnv.pas

+ 11 - 1
compiler/htypechk.pas

@@ -917,6 +917,13 @@ implementation
                        (todef.size>fromdef.size) then
                      CGMessagePos2(hp.fileinfo,type_e_typecast_wrong_size_for_assignment,tostr(fromdef.size),tostr(todef.size));
                   end;
+                 { don't allow assignments to typeconvs that need special code }
+                 if not(gotsubscript or gotvec or gotderef) and
+                    not(ttypeconvnode(hp).assign_allowed) then
+                   begin
+                     CGMessagePos(hp.fileinfo,type_e_argument_cant_be_assigned);
+                     exit;
+                   end;
                  case hp.resulttype.def.deftype of
                    pointerdef :
                      gotpointer:=true;
@@ -1915,7 +1922,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.86  2004-05-16 13:29:46  peter
+  Revision 1.87  2004-05-23 15:03:40  peter
+    * some typeconvs don't allow assignment or passing to var para
+
+  Revision 1.86  2004/05/16 13:29:46  peter
     * forbid more overloaded operators with orddef/enumdef
 
   Revision 1.85  2004/04/18 07:52:43  florian

+ 28 - 1
compiler/ncnv.pas

@@ -51,6 +51,7 @@ interface
           function det_resulttype:tnode;override;
           procedure mark_write;override;
           function docompare(p: tnode) : boolean; override;
+          function assign_allowed:boolean;
           procedure second_call_helper(c : tconverttype);
        private
           function resulttype_int_to_int : tnode;
@@ -1935,6 +1936,29 @@ implementation
       end;
 
 
+    function ttypeconvnode.assign_allowed:boolean;
+      begin
+        result:=(convtype=tc_equal) or
+                { typecasting from void is always allowed }
+                is_void(left.resulttype.def) or
+                (left.resulttype.def.deftype=formaldef) or
+                { int 2 int with same size reuses same location, or for
+                  tp7 mode also allow size < orignal size }
+                (
+                 (convtype=tc_int_2_int) and
+                 (
+                  (resulttype.def.size=left.resulttype.def.size) or
+                  ((m_tp7 in aktmodeswitches) and
+                   (resulttype.def.size<left.resulttype.def.size))
+                 )
+                ) or
+                { int 2 bool/bool 2 int, explicit typecast, see also nx86cnv }
+                ((convtype in [tc_int_2_bool,tc_bool_2_int]) and
+                 (nf_explicit in flags) and
+                 (resulttype.def.size=left.resulttype.def.size));
+      end;
+
+
     function ttypeconvnode.docompare(p: tnode) : boolean;
       begin
         docompare :=
@@ -2423,7 +2447,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.145  2004-05-23 14:14:18  florian
+  Revision 1.146  2004-05-23 15:03:40  peter
+    * some typeconvs don't allow assignment or passing to var para
+
+  Revision 1.145  2004/05/23 14:14:18  florian
     + added set of widechar support (limited to 256 chars, is delphi compatible)
 
   Revision 1.144  2004/04/29 19:56:37  daniel