View Issue Details

IDProjectCategoryView StatusLast Update
0024184FPCCompilerpublic2013-04-07 14:19
ReporterWicked Assigned ToJonas Maebe  
PrioritylowSeveritycrashReproducibilityalways
Status resolvedResolutionfixed 
PlatformWin64OSWindows 7 x64 
Product Version2.7.1 
Fixed in Version3.0.0 
Summary0024184: SIGSEGV while interface assigment
DescriptionI use the interface forward declaration like this:

  IBroadCaster = interface;

  { TBroadCaster }

  TBroadCaster = class(TInterfacedObject, IBroadCaster)
  private
    FEnable: boolean;
    FEvents: TEventsList;
    FSender: TObject;
  public
    function GetEnable: boolean;
    function GetEvents: TEventsList;
    function GetSender: TObject;
    procedure SetEnable(AValue: boolean);
    procedure SetSender(AValue: TObject);

    procedure Invoke;
    procedure Subscribe(const AEvent: TNotifyEvent);
    procedure UnSubscribe(const AEvent: TNotifyEvent);
    property Events: TEventsList read GetEvents;
    property Enable: boolean read GetEnable write SetEnable;
    property Sender: TObject read GetSender write SetSender;
    constructor Create(AOwner: TObject);
    destructor Destroy;
  end;

  IBroadCaster = interface
    function GetEnable: boolean;
    function GetEvents: TEventsList;
    function GetSender: TObject;
    procedure SetEnable(AValue: boolean);
    procedure SetSender(AValue: TObject);
    procedure Invoke;
    procedure Subscribe(const AEvent: TNotifyEvent);
    procedure UnSubscribe(const AEvent: TNotifyEvent);
    property Events: TEventsList read GetEvents;
    property Enable: boolean read GetEnable write SetEnable;
    property Sender: TObject read GetSender write SetSender;
  end;

And when I try to BroadCaster := TBroadCaster.Create(Self) (where FBroadCaster is IBroadCaster), an a SIGSEGV exception is raised.
But if you declare IBroadCaster previously no error occurs.
Tagsinterfaces
Fixed in Revision24177
FPCOldBugId
FPCTarget
Attached Files

Activities

Wicked

2013-03-31 11:43

reporter  

example.zip (2,527 bytes)

Sergei Gorelkin

2013-03-31 12:54

developer   ~0066665

The bug appears to be caused by forward definition of interface. No crash occurs if IBroadCaster is moved before TBroadcaster.

Jonas Maebe

2013-03-31 13:04

manager   ~0066666

I think the code should not compile, because the compiler cannot check that the class actually conforms to the interface. It's similar to inheriting from a forward-declared class.

Kylix 3 does compile the following code, but doesn't give an error about the missing implementation of "test". It does give the error if the interface is not forward-declared:

***
type
  ti = interface;

  tc = class(tinterfacedobject, ti)
  end;

  ti = interface
    procedure test;
  end;

begin
end.
***

Maybe this is fixed in later Delphi versions.

Jonas Maebe

2013-04-07 14:19

manager   ~0066854

The compiler now gives an error when you declare a class as conforming to a forward-declared interface. Current Delphi versions also give an error. If you have a cyclic dependency, you can solve it by forward-declaring the class instead.

Issue History

Date Modified Username Field Change
2013-03-31 11:43 Wicked New Issue
2013-03-31 11:43 Wicked File Added: example.zip
2013-03-31 11:45 Wicked Tag Attached: interfaces
2013-03-31 12:54 Sergei Gorelkin Note Added: 0066665
2013-03-31 13:04 Jonas Maebe Note Added: 0066666
2013-04-07 14:19 Jonas Maebe Fixed in Revision => 24177
2013-04-07 14:19 Jonas Maebe Note Added: 0066854
2013-04-07 14:19 Jonas Maebe Status new => resolved
2013-04-07 14:19 Jonas Maebe Fixed in Version => 2.7.1
2013-04-07 14:19 Jonas Maebe Resolution open => fixed
2013-04-07 14:19 Jonas Maebe Assigned To => Jonas Maebe