[fpc-devel] Problem (bug?) with generics

Giulio Bernardi ugilio at hotmail.com
Thu Sep 13 16:47:38 CEST 2007


Hi,
I have a problem with generics (see code at the end of the mail).
I'm trying to use a record as the type of a generic class, but
the code doesn't compile because fpc complains with:
"Error: Illegal qualifier"
on lines where I use the record fields.
I think that the compiler should raise this error only if the
class is specialized with an incompatible type.
code:

===========================================================

program genbug;

{$MODE OBJFPC}

uses
  Classes, SysUtils;

type
  TRec32 = packed record
    data1 : longword;
    data2 : longword;
  end;
  PRec32 = ^TRec32;

  TRec64 = packed record
    data1 : qword;
    data2 : qword;
  end;
  PRec64 = ^TRec64;

  generic TGenClass<_TPRec_,_TRec_> = class
  public
    constructor Create;
  end;

  TClass32 = specialize TGenClass<PRec32,TRec32>;
  TClass64 = specialize TGenClass<PRec64,TRec64>;

  constructor TGenClass.Create;
  var p : _TPRec_;
  begin
    GetMem(p,sizeof(_TRec_));
    p^.data1:=1;
    p^.data2:=2;
    FreeMem(p);
  end;


begin

end.

===========================================================

FPC raises an error on these lines:
    p^.data1:=1;
    p^.data2:=2;
Tried with 2.2.0 and 2.3.1 (svn revision 8423).

Is this a bug (should I report this to mantis?) or a feature?

bye,
Giulio

_________________________________________________________________
Don't just search. Find. Check out the new MSN Search! 
http://search.msn.com/




More information about the fpc-devel mailing list