diff --git a/.gitattributes b/.gitattributes index c179ed6824..e5ba86cd28 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11867,6 +11867,7 @@ tests/test/toperatorerror.pp svneol=native#text/plain tests/test/tover1.pp svneol=native#text/plain tests/test/tover2.pp svneol=native#text/plain tests/test/tover3.pp svneol=native#text/plain +tests/test/tover4.pas svneol=native#text/plain tests/test/tpackrec.pp svneol=native#text/plain tests/test/tparray1.pp svneol=native#text/plain tests/test/tparray10.pp svneol=native#text/plain diff --git a/compiler/defutil.pas b/compiler/defutil.pas index df8be629e1..b105d614fa 100644 --- a/compiler/defutil.pas +++ b/compiler/defutil.pas @@ -228,6 +228,9 @@ interface {# Returns true, if definition is a "real" real (i.e. single/double/extended) } function is_real(def : tdef) : boolean; + {# Returns true for single,double,extended and cextended } + function is_real_or_cextended(def : tdef) : boolean; + { true, if def is a 8 bit int type } function is_8bitint(def : tdef) : boolean; @@ -395,6 +398,13 @@ implementation end; + function is_real_or_cextended(def: tdef): boolean; + begin + result:=(def.typ=floatdef) and + (tfloatdef(def).floattype in [s32real,s64real,s80real,sc80real]); + end; + + function range_to_basetype(l,h:TConstExprInt):tordtype; begin { prefer signed over unsigned } diff --git a/compiler/htypechk.pas b/compiler/htypechk.pas index 3524c9101b..8296712769 100644 --- a/compiler/htypechk.pas +++ b/compiler/htypechk.pas @@ -2708,8 +2708,8 @@ implementation { for value and const parameters check precision of real, give penalty for loosing of precision. var and out parameters must match exactly } if not(currpara.varspez in [vs_var,vs_out]) and - is_real(def_from) and - is_real(def_to) then + is_real_or_cextended(def_from) and + is_real_or_cextended(def_to) then begin eq:=te_equal; if is_extended(def_to) then diff --git a/tests/test/tover4.pas b/tests/test/tover4.pas new file mode 100644 index 0000000000..c9a3e32e31 --- /dev/null +++ b/tests/test/tover4.pas @@ -0,0 +1,65 @@ +{ %cpu=i386,x86_64 } +{ %skiptarget=win64 } +{ Target must actually support Extended type } + +function test1(x: single): integer; +begin + test1:=1; +end; + +function test1(x: double): integer; +begin + test1:=2; +end; + +function test1(x: extended): integer; +begin + test1:=3; +end; + + +function test2(x: single): integer; +begin + test2:=1; +end; + +function test2(x: double): integer; +begin + test2:=2; +end; + + +function test3(x: single): integer; +begin + test3:=1; +end; + +function test3(x: double): integer; +begin + test3:=2; +end; + +function test3(x: cextended): integer; +begin + test3:=3; +end; + + +var + a: cextended; + b: extended; +begin + a:= 123.456; + b:= 123.456; + { test #1: single/double/extended available, passing cextended must select extended } + if test1(a)<>3 then + halt(1); + + { test #2: single and double avaiable, passing cextended must select double } + if test2(a)<>2 then + halt(2); + + { test #3: single/double/cextended available, passing extended must select cextended } + if test3(a)<>3 then + halt(3); +end.