The "specialize" keyword is accepted (and actually works normally) in {$mode Delphi} in some cases
Original Reporter info from Mantis: Akira1364
-
Reporter name:
Original Reporter info from Mantis: Akira1364
- Reporter name:
Description:
While 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 reproduce:
Attempt to compile the provided reproducer program.