D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 18842 - Wrong type for pointers to member functions
Summary: Wrong type for pointers to member functions
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL: http://dlang.org/
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-08 07:58 UTC by Ate Eskola
Modified: 2024-12-13 18:58 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Ate Eskola 2018-05-08 07:58:32 UTC
When referencing a non-static member function without using an instance to that type, the typecheck malfunctions:

import std.stdio;

struct IntPair
{   int a;
    int b;

    IntPair opBinary(string op)(IntPair other)
    {   return IntPair
        (   mixin("a " ~ op ~ " other.a"),
            mixin("b " ~ op ~ " other.b")
        );
    }
}

void main()
{   auto val = IntPair(3, 10);

    //One would think it works like this, does not compile
    //IntPair function(ref IntPair, IntPair) fp = &IntPair.opBinary!"+";
    //val.fp(val).writeln;

    //this compiles and causes undefined behaviour.
    IntPair function(IntPair) fp = &IntPair.opBinary!"+";
    fp(val).writeln;
    
    readln;
}

With D, of course you would prefer using lambdas in cases like this, and using @safe prevents doing this. But I still see no reason why you should be able to call a member funtion pointer without a member, but not with one.
Comment 1 dlangBugzillaToGithub 2024-12-13 18:58:38 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19433

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB