Hello together!

In revision 28127 I've commited the addition of a warning message when constructing an abstract class (declared as "class abstract(...) ... end"). Previously the compiler did not acknowledge that flag in any way (except for the JVM target) and so I thought it was time to add an approbiate message. This message is however not enabled by default, but you can do that by either doing a

{$warn 4122 on}

or

{$warn 4122 error}

depending on the severity you want the message to have.

Note 1: the warning needs to be active at the location where the class is instantiated, not where it is declared! So better declare the directive inside a global include file or so... (AFAIK we can't currently influence that from the command line)

Note 2: the warning will only be triggered if you call a constructor on the typename of the abstract class, but not if call a constructor of a class variable of that type. That's because in the latter case the compiler can not know the type contained in the class variable at compile time (aside from special cases which are not handled either).

E.g.

=== source begin ===

type
  TTest = class abstract
  end;
  TTestClass = class of TTest;

var
  o: TObject;
  c: TTestClass;
begin
  o := TTest.Create; // warning
  o := c.Create; // no warning
end.

=== source end ===

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to