Browse Source

Generate warning in delphi mode and error otherwise on class to classref or classref to class typecasts

Pierre Muller 2 years ago
parent
commit
6095499511
1 changed files with 16 additions and 10 deletions
  1. 16 10
      compiler/ncnv.pas

+ 16 - 10
compiler/ncnv.pas

@@ -3168,19 +3168,25 @@ implementation
                                    (nf_internal in flags)
                                    (nf_internal in flags)
                                  ))
                                  ))
                                 )
                                 )
-                               ) or ((((resultdef.typ=objectdef) and (left.resultdef.typ=classrefdef))
-                                     or ((left.resultdef.typ=objectdef) and (resultdef.typ=classrefdef)))
-                                     and not (nf_internal in flags)) then
+                               ) then
                            CGMessage2(type_e_illegal_type_conversion,left.resultdef.typename,resultdef.typename)
                            CGMessage2(type_e_illegal_type_conversion,left.resultdef.typename,resultdef.typename)
                          else
                          else
                            begin
                            begin
-                             { perform target-specific explicit typecast
-                               checks }
-                             if target_specific_explicit_typeconv then
-                               begin
-                                 result:=simplify(false);
-                                 exit;
-                               end;
+                             if ((((resultdef.typ=objectdef) and (left.resultdef.typ=classrefdef))
+                                 or ((left.resultdef.typ=objectdef) and (resultdef.typ=classrefdef)))
+                                 and not (nf_internal in flags)) then
+                               if not(m_delphi in current_settings.modeswitches) then
+                                 CGMessage2(type_e_illegal_type_conversion,left.resultdef.typename,resultdef.typename)
+                               else
+                                 begin
+                                   CGMessage2(type_w_dangerous_type_conversion,left.resultdef.typename,resultdef.typename);
+			           { perform target-specific explicit typecast checks }
+                                   if target_specific_explicit_typeconv then
+                                     begin
+                                       result:=simplify(false);
+                                       exit;
+                                     end;
+                                 end;
                            end;
                            end;
                        end;
                        end;
                    end
                    end