瀏覽代碼

* 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 -

sergei 11 年之前
父節點
當前提交
1744988962
共有 4 個文件被更改,包括 78 次插入2 次删除
  1. 1 0
      .gitattributes
  2. 10 0
      compiler/defutil.pas
  3. 2 2
      compiler/htypechk.pas
  4. 65 0
      tests/test/tover4.pas

+ 1 - 0
.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

+ 10 - 0
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 }

+ 2 - 2
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

+ 65 - 0
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.