Summary: Overloading with user-defined struct when passing by
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from 2012-01-31 03:27:32 PST ---
Overloading does not work with user-defined structs when there are two
overloaded functions receiving the struct (one by ref and one by value).

struct MyStruct {}

void fun(ref MyStruct a) {}
void fun(MyStruct a) {}

    MyStruct a;
    fun(a); // fails both match

Tested with DMD32 D Compiler v2.057 which results in the error message:
Error: function called with argument types:
matches both: MyStruct a)
and: a)

But fun(ref MyStruct a) is more specialized. Thus, it should win.
The overloading protocol is defined in section
"Function Overloading" and in TDPL Section 5.5 "Overloading". Both description
(though different in wording) specify the same behavior.

It works for int. And I assume for other built-in types as well. But I haven't

I believe this issue is important. Because it is often needed (as an
optimization to avoid the copy/move) for e.g. operator overloading.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to