View Issue Details

IDProjectCategoryView StatusLast Update
0037107FPCCompilerpublic2020-05-21 20:19
ReporterGeorge Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformLinux x64OSUbuntu 
Product Version3.0.4 
Fixed in Version3.3.1 
Summary0037107: Compiler assumes SizeOf(T) = 0 for a record constrained type parameter
DescriptionSee 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 Reproduceprogram 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.
Tagsgenerics
Fixed in Revision45457
FPCOldBugId
FPCTarget-
Attached Files

Activities

Kai Burghardt

2020-05-19 05:20

reporter   ~0122921

I think it is legit for the compiler to assume the worst.

The specialization type T could be an empty record

type
  myEmptyRecord = record
    end;

which in fact has a size of zero.

Issue History

Date Modified Username Field Change
2020-05-18 19:08 George New Issue
2020-05-18 19:19 George Tag Attached: generics
2020-05-19 05:20 Kai Burghardt Note Added: 0122921
2020-05-21 20:19 Florian Assigned To => Florian
2020-05-21 20:19 Florian Status new => resolved
2020-05-21 20:19 Florian Resolution open => fixed
2020-05-21 20:19 Florian Fixed in Version => 3.3.1
2020-05-21 20:19 Florian Fixed in Revision => 45457
2020-05-21 20:19 Florian FPCTarget => -