www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5986] New: Function pointers wrongly typed

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5986

           Summary: Function pointers wrongly typed
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: raphael.londeix gmail.com



02:36:22 PDT ---
Created an attachment (id=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 :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 12 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5986




02:52:27 PDT ---
dmd version is v2.052

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 12 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5986


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com



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();

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 06 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5986


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE



*** This issue has been marked as a duplicate of issue 3720 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 12 2011