Skip to content

extern(C++) opBinary error with getOverloads #22819

@tim-dlang

Description

@tim-dlang
extern(C++) struct S
{
    int opBinary(string op)(S rhs) if (op == "+")
    {
        return 0;
    }
    int opBinary(string op)(int rhs) if (op == "+")
    {
        return 0;
    }
    int opBinary(string op)(int rhs) if (op == "-")
    {
        return 0;
    }
}
size_t test()
{
    size_t count;
    static foreach (overload; __traits(getOverloads, S, "opBinary", true))
        static foreach(op; ["+", "-"])
            static if (__traits(compiles, overload!op))
            {
                cast(void)&overload!op;
                pragma(msg, "op=", op, " ", typeof(&overload!op));
                count++;
            }
    return count;
}
static assert(test() == 3);

DMD generates the following error:

testopbinary.d(21): Error: template instance `testopbinarymangle.S.overload!"+"` internal compiler error: C++ `string` template value parameter is not supported
            static if (__traits(compiles, overload!op))
                                          ^

The problem is that DMD uses the name "overload" instead of "opBinary" when checking for operator overloading during mangling of extern(C++).

I will make a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions