summaryrefslogtreecommitdiff
path: root/tests/webtbs/tw20192.pp
diff options
context:
space:
mode:
authorflorian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2>2011-09-29 21:17:44 +0000
committerflorian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2>2011-09-29 21:17:44 +0000
commit4abbbbb0f4b38c6114476fe34def6ea8666d919b (patch)
tree5105ad2daa81df87fb52a82b022fcdbb34978cb1 /tests/webtbs/tw20192.pp
parent02dd03cd73b8b942151d23bc6433b315ba6b057d (diff)
downloadfpc-4abbbbb0f4b38c6114476fe34def6ea8666d919b.tar.gz
* don't evaluate sizeof(<type param>) as a constant to avoid arithmetic errors in constant folding, resolves #20192
git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@19285 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'tests/webtbs/tw20192.pp')
-rw-r--r--tests/webtbs/tw20192.pp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/webtbs/tw20192.pp b/tests/webtbs/tw20192.pp
new file mode 100644
index 0000000000..67c2e18b38
--- /dev/null
+++ b/tests/webtbs/tw20192.pp
@@ -0,0 +1,47 @@
+program SizeOfBug;
+{$mode objfpc}{$H+}
+
+type
+ generic TGen<_T> = class(TObject)
+ private
+ FField: _T;
+ public
+ constructor Create(Val: _T);
+
+ function Bug: Integer;
+ end;
+
+{--- TGen.Create ---}
+constructor TGen.Create(Val: _T);
+begin
+ inherited Create;
+ FField := Val;
+end;
+
+{--- TGen.Bug ---}
+function TGen.Bug : Integer;
+begin
+ Result := 100000 div SizeOf(_T); // *** DIVISION BY ZERO ***
+
+ // THE FOLLOWING CODE IS OK !
+ //
+ // var
+ // S: Integer;
+ // begin
+ // S := SizeOf(_T);
+ // Result := 100000 div S;
+end;
+
+type
+ TGenInt = specialize TGen<Integer>;
+
+var
+ V: TGenInt;
+begin
+ V := V.Create(589);
+ WriteLn('V.Bug = ', V.Bug);
+ if V.Bug<>100000 div sizeof(pointer) then
+ halt(1);
+ V.Free;
+ writeln('ok');
+end.