Compiler reports error on usage of SizeOf of a type parameter in constant value
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: (3203) Illegal expression" at line 12.
And "Error: (5000) Identifier not found "Size"" at line 14.
Both are wrong.
The errors do not appear if T is constrained by "record" or the constant value set to only "SizeOf(T)". I.e. without operations.
FPC v3.2.0 RC1 behaviour is the same.
Steps to reproduce:
program genTest;
{$IFDEF FPC}{$mode Delphi}{$ENDIF}
type
TTest<T> = class(TObject)
procedure testit();
end;
procedure TTest<T>.testit();
const
Size = SizeOf(T) * 2;
begin
WriteLn('=== ', Size)
end;
begin
TTest<Char>.Create().TestIt();
end.
Mantis conversion info:
- Mantis ID: 37108
- OS: Ubuntu
- OS Build: 18.04.4
- Platform: Linux x64
- Version: 3.0.4