Skip to content

TCustomAttribute descendants cannot be used

Summary

TCustomAttribute descendants

WeakAttribute = class(TCustomAttribute); 
UnsafeAttribute = class(TCustomAttribute); 
RefAttribute = class(TCustomAttribute); 
VolatileAttribute = class(TCustomAttribute);

cannot be used in code because compiler complains reports an error:

Error: Wrong number of parameters specified for call to "Create"
objpas.inc(1306,34) Error: Found declaration: constructor Create;

System Information

  • Operating system: Windows
  • Processor architecture: x86-64
  • Compiler version: trunk
  • Device: Computer

Steps to reproduce

type 
  TC1 = class
  private
    [unsafe] FObj1: TObject; 
  end;

What is the current bug behavior?

Compile error.

What is the expected (correct) behavior?

No compile error.

Possible fixes

Either remove private constructor from TCustomAttribute or create public parameter-less constructor for descendants that do not need special constructors. Eg.

TSimpleCustomAttribute = class(TCustomAttribute)
public
  constructor Create;
end;

WeakAttribute = class(TSimpleCustomAttribute);
UnsafeAttribute = class(TSimpleCustomAttribute);
RefAttribute = class(TSimpleCustomAttribute);
VolatileAttribute = class(TSimpleCustomAttribute);
Edited by Sven/Sarah Barth
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information