mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-07 01:48:00 +02:00

Please note that Delphi has the exact same bug as we have and thus code working in FPC will not work in Delphi. Additionally taking the method address of a local variable or a local/global constant for a method pointer is dangerous as the variable (in case of constants is a temporary local variable) will go out of scope once the containing procedure/function/method exits! ncgld.pas, tcgloadnode.pass_generate_code: * only use the value of Self if it is an implicit pointer object (class instance) or a class reference, but not for everything else (objects, records, primitive types) +added test git-svn-id: trunk@28160 -
39 lines
577 B
ObjectPascal
39 lines
577 B
ObjectPascal
program tw26177;
|
|
|
|
{$MODE DELPHI}
|
|
{$MODESWITCH TYPEHELPERS}
|
|
|
|
uses
|
|
Classes;
|
|
|
|
type
|
|
TInt32Helper = record helper for Int32
|
|
procedure Foo(Sender: TObject);
|
|
end;
|
|
|
|
var
|
|
value: Int32 = 0;
|
|
|
|
procedure TInt32Helper.Foo(Sender: TObject);
|
|
begin
|
|
value := Self;
|
|
end;
|
|
|
|
var
|
|
i: Int32 = 10;
|
|
m: TNotifyEvent;
|
|
begin
|
|
m := i.Foo;
|
|
// Data is equal 10 (!) but should be equal to @i
|
|
//WriteLn(Int32(TMethod(m).Data));
|
|
// TMethod(m).Data := @i; < workaround for bug
|
|
try
|
|
m(nil); // External SIGSEGV!
|
|
if value <> 10 then
|
|
Halt(2);
|
|
except
|
|
Halt(1);
|
|
end;
|
|
end.
|
|
|