Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-02

Regression? Problem passing a packed record to a overriden, virtual, abstract method in fpc 2.7.1.

9 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Reimar Grabowski

Hi,

see the following little program:

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.

Obviously the expected output is 0,0,3 but in fact the output is 0,3,3. I am sure that this used to work as my real code showing the problem is many years old. (The problem stays even if I don't declare the method in TClassA abstract.)

OS: Ubuntu 12.10 64-Bit
Compiler: FPC 2.7.1 Rev. 23655

R.

Mattias Gaertner
to Reimar Grabowski
Show quoted text 55 lines
Hi, see the following little program: 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. Obviously the expected output is 0,0,3 but in fact the output is 0,3,3. I am sure that this used to work as my real code showing the problem is many years old. (The problem stays even if I don't declare the method in TClassA abstract.) OS: Ubuntu 12.10 64-Bit Compiler: FPC 2.7.1 Rev. 23655

It works under 2.6.0 and 2.6.2 (Ubuntu 64bit).

Mattias

Mattias Gaertner
to Mattias Gaertner
Show quoted text 60 lines
On Sun, 24 Feb 2013 23:20:23 +0100 Reimar Grabowski wrote: > Hi, > > see the following little program: > > 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. > > Obviously the expected output is 0,0,3 but in fact the output is 0,3,3. > I am sure that this used to work as my real code showing the problem is many years old. > (The problem stays even if I don't declare the method in TClassA abstract.) > > OS: Ubuntu 12.10 64-Bit > Compiler: FPC 2.7.1 Rev. 23655 It works under 2.6.0 and 2.6.2 (Ubuntu 64bit).

And it works under 2.7.1 rev 23661:
TClassB: 0.000000000E+00, 0.000000000E+00, 3.000000000E+00

Mattias

Reimar Grabowski
to Reimar Grabowski
On Mon, 25 Feb 2013 22:59:26 +0100 Mattias Gaertner wrote: > And it works under 2.7.1 rev 23661:

Even with 23662 it does not work for me compiling from Lazarus. But from command line it works. So it is not a FPC problem.

Sorry for the noise.
Investigating further.
R.

Reimar Grabowski
to Reimar Grabowski
But from command line it works. So it is not a FPC problem.

I am really sorry for communicating with myself but I have spoken too early. Now I can reproduce the problem using just FPC, no Lazarus involved. It gets triggered when compiling with range checking (-Cr) or with veryfying object method call validity (-CR). At least now I know where the problem is and can workaround it by disabling both. 2.6.2 works correctly.

R.

Flávio Etrusco
to Reimar Grabowski
Reimar Grabowski wrote 10 lines
On Tue, 26 Feb 2013 00:02:33 +0100 Reimar Grabowski wrote: > But from command line it works. So it is not a FPC problem. I am really sorry for communicating with myself but I have spoken too early. Now I can reproduce the problem using just FPC, no Lazarus involved. It gets triggered when compiling with range checking (-Cr) or with veryfying object method call validity (-CR). At least now I know where the problem is and can workaround it by disabling both. 2.6.2 works correctly. R.

FWIW even with these settings I can't reproduce the bug. Not even enabling -O3 -Ou.
(FPC 2.6 on Win32, compiling from Lazarus)

-Flávio

Mattias Gaertner
to Reimar Grabowski: On Tue, 26 Feb 2013 00:02:33 +0100 I am really sorry for communicating with myself but I…
Show quoted text 6 lines
On Tue, 26 Feb 2013 00:02:33 +0100 Reimar Grabowski wrote: > But from command line it works. So it is not a FPC problem. I am really sorry for communicating with myself but I have spoken too early. Now I can reproduce the problem using just FPC, no Lazarus involved. It gets triggered when compiling with range checking (-Cr) or with veryfying object method call validity (-CR).

Please submit a bug report.

At least now I know where the problem is and can workaround it by disabling both. 2.6.2 works correctly.

Mattias