Răsfoiți Sursa

* allow enum => pointer type casts in delphi mode, resolves #8465

git-svn-id: trunk@7905 -
florian 18 ani în urmă
părinte
comite
76a3d55199
4 a modificat fișierele cu 22 adăugiri și 3 ștergeri
  1. 1 0
      .gitattributes
  2. 0 2
      compiler/defcmp.pas
  3. 18 0
      tests/webtbf/tw8465a.pp
  4. 3 1
      tests/webtbs/tw8465.pp

+ 1 - 0
.gitattributes

@@ -7381,6 +7381,7 @@ tests/webtbf/tw8150g.pp svneol=native#text/plain
 tests/webtbf/tw8264a.pp svneol=native#text/plain
 tests/webtbf/tw8398.pp svneol=native#text/plain
 tests/webtbf/tw8451.pp svneol=native#text/plain
+tests/webtbf/tw8465a.pp svneol=native#text/plain
 tests/webtbf/tw8528.pp svneol=native#text/plain
 tests/webtbf/tw8583.pp svneol=native#text/plain
 tests/webtbf/tw8588.pp svneol=native#text/plain

+ 0 - 2
compiler/defcmp.pas

@@ -933,7 +933,6 @@ implementation
                          eq:=te_convert_l1;
                        end;
                    end;
-{
                  enumdef :
                    begin
                      { allow explicit typecasts from enums to pointer.
@@ -950,7 +949,6 @@ implementation
                          eq:=te_convert_l1;
                        end;
                    end;
-}
                  arraydef :
                    begin
                      { string constant (which can be part of array constructor)

+ 18 - 0
tests/webtbf/tw8465a.pp

@@ -0,0 +1,18 @@
+{ %fail }
+program EnumPtrConvTest;
+
+{$APPTYPE CONSOLE}
+
+{$packenum 1}
+type
+  TEnum = (a, b);
+
+var
+  e: TEnum;
+  p: Pointer;
+
+begin
+  e := b;
+  p := Pointer(e);
+  WriteLn(Integer(p)); // produces "1" in Delphi
+end.

+ 3 - 1
tests/webtbs/tw8465.pp

@@ -5,6 +5,7 @@ program EnumPtrConvTest;
 {$IFDEF FPC}
   {$MODE DELPHI}
 {$ENDIF}
+{$packenum 1}
 
 type
   TEnum = (a, b);
@@ -16,5 +17,6 @@ var
 begin
   e := b;
   p := Pointer(e);
-  WriteLn(Integer(p)); // produces "1" in Delphi
+  if Integer(p)<>1 then
+    halt(1); // produces "1" in Delphi
 end.