* even if currency is handled by torddef, it is a real number, so using / is perfectly right, resolves #38718

(cherry picked from commit 09628e56cb)

# Conflicts:
#	.gitattributes
This commit is contained in:
florian 2021-04-09 20:38:46 +00:00
parent 30c6cc295c
commit 26f200b0ff
2 changed files with 13 additions and 1 deletions

View File

@ -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.}

12
tests/webtbs/tw38718.pp Normal file
View File

@ -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.