diff --git a/.gitattributes b/.gitattributes index 4e4654f636..a2cd3a55e0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/compiler/defcmp.pas b/compiler/defcmp.pas index 1977746cbc..0b9762f834 100644 --- a/compiler/defcmp.pas +++ b/compiler/defcmp.pas @@ -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 diff --git a/tests/tbf/tb0210a.pp b/tests/tbf/tb0210a.pp new file mode 100644 index 0000000000..6b85420a35 --- /dev/null +++ b/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. diff --git a/tests/tbf/tb0211a.pp b/tests/tbf/tb0211a.pp new file mode 100644 index 0000000000..c8d3a734af --- /dev/null +++ b/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. diff --git a/tests/tbs/tb0554.pp b/tests/tbs/tb0554.pp index 97847a2239..fb2f43ea56 100644 --- a/tests/tbs/tb0554.pp +++ b/tests/tbs/tb0554.pp @@ -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.