Thread overview
[Issue 7409] New: Overloading with user-defined struct when passing by ref
Jan 31, 2012
Kenji Hara
Jan 31, 2012
yebblies
January 31, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7409

           Summary: Overloading with user-defined struct when passing by
                    ref
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: jens.k.mueller@gmx.de


--- Comment #0 from jens.k.mueller@gmx.de 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) {}

unittest
{
    MyStruct a;
    fun(a); // fails both match
}

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

But fun(ref MyStruct a) is more specialized. Thus, it should win.
The overloading protocol is defined in http://dlang.org/function.html 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 checked.

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: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 31, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7409



--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2012-01-31 07:11:23 PST ---
This issue is a part of bug 5889.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 31, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7409


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies@gmail.com
         Resolution|                            |DUPLICATE


--- Comment #2 from yebblies <yebblies@gmail.com> 2012-02-01 02:46:55 EST ---
*** This issue has been marked as a duplicate of issue 4843 ***

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