Pointers to non-static member functions!

David Nadlinger see at klickverbot.at
Wed Jun 8 07:50:05 PDT 2011


Oh wow, my previous comment was total nonsense, I confused .func with 
the delegate .funcptr property…

The bugs probably comes from the delegate .funcptr property being a 
function pointer of the same signature as the delegate type itself, 
which doesn't make too much sense: 
http://d.puremagic.com/issues/show_bug.cgi?id=2672. Presumably because 
of this, &A.func also has the same type so things match up.

However, as not every delegate can be called as a function because of 
ABI reasons (think about the hidden struct return pointer), changing the 
type of delegate.funcptr to void* as well might be the better solution.

David


On 6/8/11 10:00 AM, Daniel Murphy wrote:
> Currently, this compiles:
>
> class A
> {
>      void func() {}
> }
>
> void main()
> {
>    auto p =&A.func;
> }
>
> In this case, typeof(p) is void function().
> Calling one of these pointers, of course, can easily give you a segfault as
> it completely ignores the this pointer.
> I didn't even realize you could do this until I saw
> http://d.puremagic.com/issues/show_bug.cgi?id=5986
>
> I understand that it could be useful to have a way to get the address of a
> non-static member function, but I doubt returning a malformed function
> pointer is really useful.
>
> Does anybody think changing&ClassType.nonStaticMember to return void* would
> be a bad idea?



More information about the Digitalmars-d mailing list