Class procedures work without a context pointer. This is well know, for example you won't be able to access a variable that's itself not a class var. However if you take a pointer to a class procedure, a program will allocate a fat pointer made of the entry point (address in process image) and object address (instance of the object). But the second pointer (instance of the object) is totally superfluous.
The problem is that we won't be able to cast a pointer to class procedure as a pointer to a free procedure, even if it's actually one.
We should be able to do it, as shown in this example, the object instance is not needed at all:
program Project1;
{$ASMMODE INTEL}
type
TProc = procedure();
TTempProc = procedure() of object;
TFoo = class
class var a: integer;
class procedure foo();
end;
var
proc: TProc;
tempproc: TTempProc;
Foo: TFoo;
class procedure TFoo.foo();
begin
writeln('works');
a := 8;
writeln(a);
end;
function toProc(a: pointer): TProc; assembler;
asm
{$IFDEF CPU64}
mov rax, [a];
{$ELSE}
mov eax, [a];
{$ENDIF}
end;
begin
Foo := TFoo.Create;
// not allowed because this returns a procedure of object
//proc := toProc(@tempproc);
tempproc := @Foo.foo;
proc := toProc(@tempproc);
proc();
readln;
end.
So what's the rationale for the pointers to class proc being some pointer to object proc ?
It looks like an error, no ? Do you have a counter example where the cast would be unsafe ?
Otherwise, I'll file an issue.