View Issue Details

IDProjectCategoryView StatusLast Update
0035981FPCCompilerpublic2019-08-23 17:03
ReporterAkira1364Assigned ToSven Barth 
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;

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

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

  destructor TFoo<T>.Destroy;
    inherited Destroy;

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

  with Test<TStrings> do begin
Steps To ReproduceAttempt to compile the provided reproducer program.
Fixed in Revision42776
Attached Files


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