Bug 5986 – Function pointers wrongly typed

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2011-05-12T02:36:00Z
Last change time
2011-06-12T22:09:28Z
Assigned to
nobody
Creator
raphael.londeix

Attachments

IDFilenameSummaryContent-TypeSize
967bound_method_bug_report.dfull example to reproducetext/x-dsrc746

Comments

Comment #0 by raphael.londeix — 2011-05-12T02:36:22Z
Created attachment 967 full example to reproduce Hi, When using auto, the wrong type is infered from the expression &Class.method. I have to fully specify the type. However, even when I do that, the typeid does not include any information of the argument type (which is Class). Class a; auto f = &Class.method; // void()* f(); // Segfault, imho it's normal f(a); // compile error void function(Class) f2 = &Class.method; // Still void()* ! f2(a); // fine :) See snippet for full example :)
Comment #1 by raphael.londeix — 2011-05-12T02:52:27Z
dmd version is v2.052
Comment #2 by yebblies — 2011-06-06T21:04:57Z
The reason the second method works is because of issue 3797. The fact that &ClassType.nonstaticmethod returns an invalid function pointer is definitely a bug. But what should it do? I see the following options: 1. Disallow it completely - you can still get the address from a delegate's function pointer 2. Make it return void* 3. Make it return a callable function pointer that matches the abi for member function calls. I'm not sure what sensible use cases there are for getting the address of a member function, but 1 seems the most reasonable. The original bug report asks for 3, but that does not seem particularly useful. eg. auto funcptr = &Class.func; auto instance = new Class(); funcptr(instance); vs auto instance = new Class(); instance.func();
Comment #3 by yebblies — 2011-06-12T22:09:28Z
*** This issue has been marked as a duplicate of issue 3720 ***