Compiler assumes SizeOf(T) = 0 for a record constrained type parameter
Original Reporter info from Mantis: avagames @avagames
-
Reporter name: George
Original Reporter info from Mantis: avagames @avagames
- Reporter name: George
Description:
See example.
Compiler reports "Error: (3138) Division by zero" at line 12.
And "Warning: (6018) unreachable code" at line 14.
Both are wrong.
FPC v3.2.0 behaviour is the same.
Steps to reproduce:
program genTest;
{$IFDEF FPC}{$mode Delphi}{$ENDIF}
type
TTest<T: Record> = class(TObject)
procedure testit();
end;
procedure TTest<T>.testit();
begin
WriteLn('=== ', 1 div SizeOf(T));
if SizeOf(T) > 0 then
WriteLn('I''m reachable!')
end;
begin
TTest<Char>.Create().TestIt();
end.
Mantis conversion info:
- Mantis ID: 37107
- OS: Ubuntu
- OS Build: 18.04.4
- Platform: Linux x64
- Version: 3.0.4
- Fixed in version: 3.3.1
- Fixed in revision: 45457 (#51da4707)