mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-16 01:39:27 +02:00
* Modified behavior of CExtended type in overload selection: it is made more compatible to Extended than to Double and Single. Also an Extended parameter selects a CExtended overload (if available) instead of Double.
+ Test. git-svn-id: trunk@27366 -
This commit is contained in:
parent
eb984a5adb
commit
1744988962
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -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
|
||||
|
@ -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 }
|
||||
|
@ -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
|
||||
|
65
tests/test/tover4.pas
Normal file
65
tests/test/tover4.pas
Normal file
@ -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.
|
Loading…
Reference in New Issue
Block a user