application crashes trying to assign class methods
Original Reporter info from Mantis: jcmoraisjr
-
Reporter name: Joao Morais
Original Reporter info from Mantis: jcmoraisjr
- Reporter name: Joao Morais
Description:
The following code crashes the application. The same code with the second_test directive crashes the application under -O2 and -O3. Win32 and Linux. Note, also, that the compiler thinks that I am not using the VClass variable.
--
Joao Morais
Additional information:
program Optimize;
{$mode objfpc}{$H+}
{.$define second_test}
type
TTestClass = class of TTestBase;
TTestBase = class(TObject)
public
class function ClassMetadataStr: string;
class function InternalMetadataStr: string; virtual;
end;
TTestImpl = class(TTestBase)
public
class function InternalMetadataStr: string; override;
end;
class function TTestBase.ClassMetadataStr: string;
var
VMetadataMethod, VParentMetadataMethod: function: string of object;
{$ifdef second_test}
VClass: TTestClass;
{$endif}
begin
if Self <> TTestBase then
begin
writeln('pass 1');
VMetadataMethod := @InternalMetadataStr;
writeln('pass 2');
{$ifndef second_test}
VParentMetadataMethod := @TTestClass(ClassParent).InternalMetadataStr;
{$else}
VClass := TTestClass(ClassParent);
writeln('pass 2.1');
VParentMetadataMethod := @VClass.InternalMetadataStr;
{$endif}
writeln('pass 3');
if TMethod(VMetadataMethod).Code <> TMethod(VParentMetadataMethod).Code then
Result := InternalMetadataStr;
writeln('pass 4');
end else
Result := 'base result';
end;
class function TTestBase.InternalMetadataStr: string;
begin
Result := '';
end;
class function TTestImpl.InternalMetadataStr: string;
begin
Result := 'some stuff';
end;
var
VTestClass: TTestClass;
begin
VTestClass := TTestBase;
writeln('TTestBase result:');
writeln(VTestClass.ClassMetadataStr);
writeln;
VTestClass := TTestImpl;
writeln('TTestImpl result:');
writeln(VTestClass.ClassMetadataStr);
end.
Mantis conversion info:
- Mantis ID: 9139
- Fixed in version: 2.2.2
- Fixed in revision: 8430 (#30014fb6)
- Monitored by: » jcmoraisjr (Joao Morais)