+ 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 -
This commit is contained in:
Jonas Maebe 2009-05-16 11:07:09 +00:00
parent 47c28c2db3
commit 3a8b29be91
5 changed files with 39 additions and 3 deletions

2
.gitattributes vendored
View File

@ -6688,7 +6688,9 @@ tests/tbf/tb0207.pp svneol=native#text/plain
tests/tbf/tb0208.pp svneol=native#text/plain
tests/tbf/tb0209.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/tb0211a.pp svneol=native#text/plain
tests/tbf/tb0212.pp svneol=native#text/plain
tests/tbf/tb0213.pp svneol=native#text/plain
tests/tbf/tb0214.pp svneol=native#text/plain

View File

@ -276,7 +276,9 @@ implementation
end;
objectdef:
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
eq:=te_convert_l1;
if (fromtreetype=niln) then

17
tests/tbf/tb0210a.pp Normal file
View File

@ -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
tests/tbf/tb0211a.pp Normal file
View File

@ -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.

View File

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