View Issue Details

IDProjectCategoryView StatusLast Update
0035981FPCCompilerpublic2019-08-23 17:03
ReporterAkira1364Assigned ToSven Barth 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformx86_64OSWindowsOS Version10
Product Version3.3.1Product BuildTrunk 
Target VersionFixed in Version3.3.1 
Summary0035981: The "specialize" keyword is accepted (and actually works normally) in {$mode Delphi} in some cases
DescriptionWhile playing around with Silvio's bug example from issue 0035943, I came across this approach that pretty clearly shouldn't work, but does, printing the output you'd think it would (that being "TStrings"):

program BugExample;

{$mode Delphi}

uses Classes;

type
  TFoo<T: TPersistent> = class(TPersistent)
  public
    C: T;
    constructor Create;
    destructor Destroy; override;
  end;

  constructor TFoo<T>.Create;
  begin
    inherited Create;
    C := T.Create;
  end;

  destructor TFoo<T>.Destroy;
  begin
    C.Free;
    inherited Destroy;
  end;

  // note the *working* specialize here, in {$mode Delphi} !!!
  function Test<T: TPersistent>: specialize TFoo<T>;
  begin
    Result := TFoo<T>.Create;
  end;

begin
  with Test<TStrings> do begin
    WriteLn(C.ClassName);
    Free;
  end;
end.
Steps To ReproduceAttempt to compile the provided reproducer program.
Tagsgenerics
Fixed in Revision42776
FPCOldBugId
FPCTarget-
Attached Files

Activities

Sven Barth

2019-08-23 17:03

manager   ~0117804

That definitely should not work. Seems like two locations missed the checks for mode Delphi there... ^^'

Please test and close if okay.

Issue History

Date Modified Username Field Change
2019-08-19 17:16 Akira1364 New Issue
2019-08-19 17:17 Akira1364 Tag Attached: generics
2019-08-23 17:03 Sven Barth Assigned To => Sven Barth
2019-08-23 17:03 Sven Barth Status new => resolved
2019-08-23 17:03 Sven Barth Resolution open => fixed
2019-08-23 17:03 Sven Barth Fixed in Version => 3.3.1
2019-08-23 17:03 Sven Barth Fixed in Revision => 42776
2019-08-23 17:03 Sven Barth FPCTarget => -
2019-08-23 17:03 Sven Barth Note Added: 0117804