Bläddra i källkod

+ test conversion from class to differently sized enum and to differently
sized integer (succeed for Delphi, fail for objfpc)
* fixed compiler so it only allows typecasting a class/interface to a
differently sized integer in Delphi mode

git-svn-id: trunk@13152 -

Jonas Maebe 16 år sedan
förälder
incheckning
3a8b29be91
5 ändrade filer med 39 tillägg och 3 borttagningar
  1. 2 0
      .gitattributes
  2. 3 1
      compiler/defcmp.pas
  3. 17 0
      tests/tbf/tb0210a.pp
  4. 13 0
      tests/tbf/tb0211a.pp
  5. 4 2
      tests/tbs/tb0554.pp

+ 2 - 0
.gitattributes

@@ -6688,7 +6688,9 @@ tests/tbf/tb0207.pp svneol=native#text/plain
 tests/tbf/tb0208.pp svneol=native#text/plain
 tests/tbf/tb0208.pp svneol=native#text/plain
 tests/tbf/tb0209.pp svneol=native#text/plain
 tests/tbf/tb0209.pp svneol=native#text/plain
 tests/tbf/tb0210.pp svneol=native#text/plain
 tests/tbf/tb0210.pp svneol=native#text/plain
+tests/tbf/tb0210a.pp svneol=native#text/plain
 tests/tbf/tb0211.pp svneol=native#text/plain
 tests/tbf/tb0211.pp svneol=native#text/plain
+tests/tbf/tb0211a.pp svneol=native#text/plain
 tests/tbf/tb0212.pp svneol=native#text/plain
 tests/tbf/tb0212.pp svneol=native#text/plain
 tests/tbf/tb0213.pp svneol=native#text/plain
 tests/tbf/tb0213.pp svneol=native#text/plain
 tests/tbf/tb0214.pp svneol=native#text/plain
 tests/tbf/tb0214.pp svneol=native#text/plain

+ 3 - 1
compiler/defcmp.pas

@@ -276,7 +276,9 @@ implementation
                    end;
                    end;
                  objectdef:
                  objectdef:
                    begin
                    begin
-                     if is_class_or_interface_or_dispinterface(def_from) and (cdo_explicit in cdoptions) then
+                     if (m_delphi in current_settings.modeswitches) and
+                        is_class_or_interface_or_dispinterface(def_from) and
+                        (cdo_explicit in cdoptions) then
                       begin
                       begin
                         eq:=te_convert_l1;
                         eq:=te_convert_l1;
                         if (fromtreetype=niln) then
                         if (fromtreetype=niln) then

+ 17 - 0
tests/tbf/tb0210a.pp

@@ -0,0 +1,17 @@
+{ %fail }
+
+// check whether enums can NOT be casted to object references; this 
+// should NOT work in objfpc mode (see also tbs/tb0554.pp)
+{$mode objfpc}
+
+{$packenum 2}
+type
+  TEnum = (a, b, c);
+  
+var
+  e : TEnum;
+  o : TObject;
+
+begin
+  e := TEnum(o);
+end.

+ 13 - 0
tests/tbf/tb0211a.pp

@@ -0,0 +1,13 @@
+{ %fail }
+
+// check whether integers can NOT be casted to object references; this 
+// should NOT work in objfpc mode (see also tbs/tb0554.pp)
+{$mode objfpc}
+
+var
+  i : Word;
+  o : TObject;
+
+begin
+  i := Word(o);
+end.

+ 4 - 2
tests/tbs/tb0554.pp

@@ -1,16 +1,18 @@
 // check whether enums and integers can be casted to object references; this 
 // check whether enums and integers can be casted to object references; this 
 // should work in Delphi mode (is Delphi compatible)
 // should work in Delphi mode (is Delphi compatible)
 {$mode delphi}
 {$mode delphi}
-
+{$packenum 2}
 type
 type
   TEnum = (a, b, c);
   TEnum = (a, b, c);
   
   
 var
 var
-  i : Integer;
+  i : Word;
   e : TEnum;
   e : TEnum;
   o : TObject;
   o : TObject;
 
 
 begin
 begin
   o := TObject(e);
   o := TObject(e);
   o := TObject(i);
   o := TObject(i);
+  i := Word(o);
+  e := TEnum(o);
 end.
 end.