From 26f200b0ff4c66dab1afb980fb0d9399ffa637aa Mon Sep 17 00:00:00 2001 From: florian <florian@freepascal.org> Date: Fri, 9 Apr 2021 20:38:46 +0000 Subject: [PATCH] * 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 --- compiler/ncnv.pas | 2 +- tests/webtbs/tw38718.pp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/webtbs/tw38718.pp diff --git a/compiler/ncnv.pas b/compiler/ncnv.pas index 1525e809ba..e475acd542 100644 --- a/compiler/ncnv.pas +++ b/compiler/ncnv.pas @@ -937,7 +937,7 @@ implementation {An attempt to convert the result of a floating point division (with the / operator) to an integer type will fail. Give a hint 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); {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.} diff --git a/tests/webtbs/tw38718.pp b/tests/webtbs/tw38718.pp new file mode 100644 index 0000000000..5a0a3e39d1 --- /dev/null +++ b/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. \ No newline at end of file