Browse Source

* compare floating point default parameter values bytewise instead of as
floating point values, so that NaNs can also be compared (mantis #30299)

git-svn-id: trunk@34597 -

Jonas Maebe 8 years ago
parent
commit
94d7a7274b
4 changed files with 21 additions and 4 deletions
  1. 1 0
      .gitattributes
  2. 1 1
      compiler/defcmp.pas
  3. 6 3
      compiler/symutil.pas
  4. 13 0
      tests/webtbs/tw30299.pp

+ 1 - 0
.gitattributes

@@ -15219,6 +15219,7 @@ tests/webtbs/tw30208.pp svneol=native#text/pascal
 tests/webtbs/tw3023.pp svneol=native#text/plain
 tests/webtbs/tw30240.pp svneol=native#text/plain
 tests/webtbs/tw3028.pp svneol=native#text/plain
+tests/webtbs/tw30299.pp svneol=native#text/plain
 tests/webtbs/tw30310.pp svneol=native#text/plain
 tests/webtbs/tw30329.pp -text svneol=native#text/plain
 tests/webtbs/tw30357.pp svneol=native#text/pascal

+ 1 - 1
compiler/defcmp.pas

@@ -2181,7 +2181,7 @@ implementation
                   if assigned(currpara1.defaultconstsym) and
                      assigned(currpara2.defaultconstsym) then
                     begin
-                      if not equal_constsym(tconstsym(currpara1.defaultconstsym),tconstsym(currpara2.defaultconstsym)) then
+                      if not equal_constsym(tconstsym(currpara1.defaultconstsym),tconstsym(currpara2.defaultconstsym),true) then
                         exit;
                     end
                   { cannot have that the second (= implementation) has a default value declared and the

+ 6 - 3
compiler/symutil.pas

@@ -30,7 +30,7 @@ interface
 
     function is_funcret_sym(p:TSymEntry):boolean;
 
-    function equal_constsym(sym1,sym2:tconstsym):boolean;
+    function equal_constsym(sym1,sym2:tconstsym; nanequal: boolean):boolean;
 
 
 implementation
@@ -48,7 +48,7 @@ implementation
       end;
 
 
-    function equal_constsym(sym1,sym2:tconstsym):boolean;
+    function equal_constsym(sym1,sym2:tconstsym; nanequal: boolean):boolean;
       var
         p1,p2,pend : pchar;
       begin
@@ -85,7 +85,10 @@ implementation
                  equal_constsym:=true;
              end;
            constreal :
-             equal_constsym:=(pbestreal(sym1.value.valueptr)^=pbestreal(sym2.value.valueptr)^);
+             if nanequal then
+               equal_constsym:=CompareByte(pbestreal(sym1.value.valueptr)^,pbestreal(sym2.value.valueptr)^,sizeof(pbestreal^))=0
+             else
+               equal_constsym:=pbestreal(sym1.value.valueptr)^=pbestreal(sym2.value.valueptr)^;
            constset :
              equal_constsym:=(pnormalset(sym1.value.valueptr)^=pnormalset(sym2.value.valueptr)^);
            constnil :

+ 13 - 0
tests/webtbs/tw30299.pp

@@ -0,0 +1,13 @@
+{ %norun }
+
+{$mode objfpc}
+uses math;
+
+procedure test(s: single = NaN); forward;
+
+procedure test(s: single = NaN);
+begin
+end;
+
+begin
+end.