Просмотр исходного кода

* even if currency is handled by torddef, it is a real number, so using / is perfectly right, resolves #38718
(cherry picked from commit 09628e56cbe6ae513c2d1530514531ad6314bb0a)

# Conflicts:
# .gitattributes

florian 4 лет назад
Родитель
Сommit
26f200b0ff
2 измененных файлов с 13 добавлено и 1 удалено
  1. 1 1
      compiler/ncnv.pas
  2. 12 0
      tests/webtbs/tw38718.pp

+ 1 - 1
compiler/ncnv.pas

@@ -937,7 +937,7 @@ implementation
          {An attempt to convert the result of a floating point division
          {An attempt to convert the result of a floating point division
           (with the / operator) to an integer type will fail. Give a hint
           (with the / operator) to an integer type will fail. Give a hint
           to use the div operator.}
           to use the div operator.}
-         if (node.nodetype=slashn) and (def.typ=orddef) then
+         if (node.nodetype=slashn) and (def.typ=orddef) and not(is_currency(def)) then
            cgmessage(type_h_use_div_for_int);
            cgmessage(type_h_use_div_for_int);
          {In expressions like int64:=longint+longint, an integer overflow could be avoided
          {In expressions like int64:=longint+longint, an integer overflow could be avoided
           by simply converting the operands to int64 first. Give a hint to do this.}
           by simply converting the operands to int64 first. Give a hint to do this.}

+ 12 - 0
tests/webtbs/tw38718.pp

@@ -0,0 +1,12 @@
+{ %opt=-vh -Seh }
+program CurrencyTest;
+{$mode objfpc}{$H+}
+var
+  C: Currency;
+  D: Integer;
+begin
+  C := 1234.56;
+  D := 2;
+  C := C / D; // Hint: Use DIV instead to get an integer result
+  Writeln(C);
+end.