C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Allow conversion of memfunc pointers to func pointers

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 08 Jan 2024 16:59:46 -0300
On Monday, 8 January 2024 15:16:46 -03 Frederick Virchanza Gotham via Std-
Proposals wrote:
> I had hoped two things:
>
> (1) That a member function pointer could be reduced to just a function
> pointer

It technically can, because there's always an entry point, provided that:
 a) the this pointer is passed appropriately according to ABI rules
 b) the this pointer is passed of the correct type

(a) can be fixed with thunks or a calling-convention converter, which your
special invoker function could do.

The problem with (b) is that people want to use an overriding class' function
(virtual or not) with a base pointer. That can also be solved with a thunk,
but it breaks pointer-equality, in particular across DLL boundaries. IMO, you
should require the correct object type and avoid thunks completely.

> (2) That the address of the implementation of a virtual function could be
> ascertained without invoking the member function

It can be by reading the vtable. But again pointer-equality problems because
the entry point of the function you de-virtualised may be that of the thunk
instead of the actual function.

> Looking at how member function pointers are implemented though on some
> computers (e.g. v-table offset + delta this), it seems that goal No. 1
> wouldn't be attainable without also keeping the type information.
>
> So I'm scrapping this idea and will go back to peddling std::unaligned.


-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2024-01-08 19:59:55