From edfb31c0202737f98de5d7d30e664856b70de235 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Fri, 26 Nov 2010 15:37:31 +0000 Subject: [PATCH] * when looking for overloaded conversion (assignment) operators, only ignore those for variants. All defined operators are guaranteed to be valid by the code that checks them when they are defined (mantis #17846) git-svn-id: trunk@16449 - --- .gitattributes | 1 + compiler/defcmp.pas | 3 +-- tests/webtbs/tw17846.pp | 48 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 tests/webtbs/tw17846.pp diff --git a/.gitattributes b/.gitattributes index 598ccbbfd1..97061bcc0e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10749,6 +10749,7 @@ tests/webtbs/tw17715.pp svneol=native#text/plain tests/webtbs/tw1779.pp svneol=native#text/plain tests/webtbs/tw1780.pp svneol=native#text/plain tests/webtbs/tw17836.pp svneol=native#text/plain +tests/webtbs/tw17846.pp svneol=native#text/plain tests/webtbs/tw17862.pp svneol=native#text/plain tests/webtbs/tw17907/main/main.pas svneol=native#text/plain tests/webtbs/tw17907/test.bat svneol=native#text/plain diff --git a/compiler/defcmp.pas b/compiler/defcmp.pas index 99deca5220..f4d932cd40 100644 --- a/compiler/defcmp.pas +++ b/compiler/defcmp.pas @@ -1476,8 +1476,7 @@ implementation { Check for operators? } ( (cdo_check_operator in cdoptions) and - ((def_from.typ in [objectdef,recorddef,arraydef,stringdef]) or - (def_to.typ in [objectdef,recorddef,arraydef,stringdef])) + ((def_from.typ<>variantdef) or (def_to.typ<>variantdef)) ) ) then begin diff --git a/tests/webtbs/tw17846.pp b/tests/webtbs/tw17846.pp new file mode 100644 index 0000000000..86e50cb47e --- /dev/null +++ b/tests/webtbs/tw17846.pp @@ -0,0 +1,48 @@ +program opoverload; + +{$mode objfpc} + +const + IntValue1 = $1; + IntValue2 = $2; + IntValue3 = $4; + +type + TMyEnum = (Value1, Value2, Value3); + TMySet = set of TMyEnum; + +operator := (aRight: LongWord) aLeft: TMySet; +begin + aLeft := []; + if aRight and IntValue1 <> 0 then + Include(aLeft, Value1); + if aRight and IntValue2 <> 0 then + Include(aLeft, Value2); + if aRight and IntValue3 <> 0 then + Include(aLeft, Value3); +end; + +operator := (aRight: TMySet) aLeft: LongWord; +begin + aLeft := 0; + if Value1 in aRight then + aLeft := aLeft or IntValue1; + if Value2 in aRight then + aLeft := aLeft or IntValue2; + if Value3 in aRight then + aLeft := aLeft or IntValue3; +end; + +var + i: LongWord; + t: TMySet; +begin + i := IntValue1 or IntValue3; + t := i; + if t<>[value1,value3] then + halt(1); + i:=0; + i:=t; + if i<>(IntValue1 or IntValue3) then + halt(2); +end.