Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi    [ Add a report in this area ]  
Report #:  120830   Status: Closed
Compiler sometimes does not track that the method changed from static to virtual
Project:  Delphi Build #:  5, ... XE5
Version:    19.0 Submitted By:   Maxim Vlasov
Report Type:  Crash / Data loss / Total failure Date Reported:  11/28/2013 4:26:40 AM
Severity:    Infrequently encountered problem Last Updated: 4/15/2014 6:35:46 PM
Platform:    All versions Internal Tracking #:   45604
Resolution: Fixed (Resolution Comments) Resolved in Build: : XE6
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: 10
Description
This appears when several objects in the inheritance path are spread amongst several modules. In this case if one appends virtual to a previously static method then compile the project (Ctrl-F9, so no build) the call to this method produces a crash

Seem like this bug existed for a long time, at least Delphi 5 and 2007 both produces run-time errors, but maybe with a different messages
Steps to Reproduce:
1. Create the following 3 units (pas) and a project (dpr) (delimited here by multiply %). The final list is uRootUnit.pas, uUnitY.pas, uUnitZ.pas,
VirtualBugTest.dpr
2. Add VirtualBugTest.dpr to the Delphi
3. Compile and run, everything is ok, we returned immediately to the IDE (no message loop or interactivity here)
4. Go to TRootObject, uncomment the "virtual" keyword
5. Save unit and compile the project (Ctrl-F9)
6. Run, notice a crash  on the Clear line
(VirtualBugTest raised exception class $C0000005 with access violation at 0x00000000, read of address 0x00000000).
7. Build the project and run. Everyting is back to normal.

--------
unit uRootunit;

interface

type
  TRootObject = class
  public
    procedure Clear; virtual; { this 'virtual;' should be uncommented for bug to appear }
  end;

implementation

{ TRootObject }
procedure TRootObject.Clear;
begin
end;

end.
--------

--------
unit uUnitY;

interface uses uRootUnit;

type
  TObjFromRoot = class(TRootObject)
  end;

implementation

end.
--------

--------
unit uUnitZ;

interface uses uUnitY;

type
  TObjToBeCreated = class(TObjFromRoot)
  end;

function CreateTestObj: TObjToBeCreated;

implementation

function CreateTestObj: TObjToBeCreated;
begin
  Result:=TObjToBeCreated.Create;
end;

end.
--------

--------
program VirtualBugTest;

uses
  uUnitZ;

var
  Obj: TObjToBeCreated;

begin
  Obj:=CreateTestObj;
  Obj.Clear;
  Obj.Free
end.
--------
Workarounds
None
Attachment
120830.zip
Comments

None

Server Response from: ETNACODE01