[fpc-pascal] Generics: constructor restriction fail
    silvioprog 
    silvioprog at gmail.com
       
    Fri Oct 31 00:04:24 CET 2014
    
    
  
Hello,
Following this article:
http://alex.ciobanu.org/?p=51
The compiler does not check the constructor restriction.
Try this test:
{$mode delphi}
  TTest = class
  private // hidding the constructor to cause a compiler error
    constructor Create;
  end;
  TGen<T: class, constructor> = class
  end;
constructor TTest.Create;
begin
end;
var  Gen: TGen<TTest>;
begin
  Gen := TGen<TTest>.Create;
end;
It compiles well in FPC (from trunk), but the same code in XE is:
"[dcc32 Error] Unit1.pas(36): E2513 Type parameter 'T' must have one public
parameterless constructor named Create"
It is a bug in FPC or I need to enable some directive switch?
Thank you!
-- 
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20141030/c6539756/attachment.html>
    
    
More information about the fpc-pascal
mailing list