When passing a packed record to a overridden, virtual method the method argument contains incorrect values
Original Reporter info from Mantis: reimgrab
-
Reporter name: Reimar Grabowski
Original Reporter info from Mantis: reimgrab
- Reporter name: Reimar Grabowski
Description:
When overriding a virtual method which takes a packed record as argument and compiling the program either with -Cr or -CR the record contains incorrect values inside the method.
Steps to reproduce:
program argumentbug;
{$MODE ObjFpc}
uses classes;
type
TVector3 = packed record
X, Y, Z: Single;
end;
TClassA = class
protected
fVector: TVector3;
public
procedure SetVector(AVector: TVector3); virtual; abstract;
end;
{ TClassB }
TClassB = class(TClassA)
public
procedure SetVector(AVector: TVector3); override;
end;
{ TClassB }
procedure TClassB.SetVector(AVector: TVector3);
begin
writeln('TClassB: ',AVector.X,',',AVector.Y,',',AVector.Z);
fVector:=AVector;
end;
var
MyVector: TVector3;
MyClassB: TClassB;
begin
MyVector.X:=0;
MyVector.Y:=0;
MyVector.Z:=3;
MyClassB:=TClassB.Create;
MyClassB.SetVector(MyVector);
end.
Compile with either -Cr or -CR and run.
Output:
TClassB: 0.000000000E+00, 3.000000000E+00, 3.000000000E+00
Expected output:
TClassB: 0.000000000E+00, 0.000000000E+00, 3.000000000E+00
Additional information:
Although the method in the example code is abstract the problem stays even if the method is not abstract and only virtual.
Mantis conversion info:
- Mantis ID: 23962
- OS: Ubuntu
- OS Build: 12.10
- Build: svn rev 23662
- Platform: x86_64
- Version: 2.7.1
- Fixed in version: 2.6.4
- Fixed in revision: 25917 (#74627768)