summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflorian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-04-09 20:38:46 +0000
committerflorian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-04-09 20:38:46 +0000
commit40b61dc251e017f2b1fb2d0cca36956a8adfb7f1 (patch)
treee1374270d77dcc0a98d1728404006bedaa7f4891
parent538b38de31c30cdcdceb61dcb85724dceda472c8 (diff)
downloadfpc-40b61dc251e017f2b1fb2d0cca36956a8adfb7f1.tar.gz
* even if currency is handled by torddef, it is a real number, so using / is perfectly right, resolves #38718
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@49154 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r--compiler/ncnv.pas2
-rw-r--r--tests/webtbs/tw38718.pp12
2 files changed, 13 insertions, 1 deletions
diff --git a/compiler/ncnv.pas b/compiler/ncnv.pas
index 5fa5ce714b..4182b2d3ad 100644
--- a/compiler/ncnv.pas
+++ b/compiler/ncnv.pas
@@ -942,7 +942,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