Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong type for pointers to member functions #19433

Open
dlangBugzillaToGithub opened this issue May 8, 2018 · 0 comments
Open

Wrong type for pointers to member functions #19433

dlangBugzillaToGithub opened this issue May 8, 2018 · 0 comments

Comments

@dlangBugzillaToGithub
Copy link

Ate Eskola (@dukc) reported this on 2018-05-08T07:58:32Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=18842

Description

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant