www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7513] New: [TDPL] opAssign examples don't work as described

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7513

           Summary: [TDPL] opAssign examples don't work as described
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: mrmocool gmx.de



import std.algorithm;
struct Widget
{
    private int[] array;
    this(uint length)
    {
        array = new int[length];
    }

    this (this)
    {
        array = array.dup;
    }

    ref Widget opAssign(ref Widget rhs)
    {
        array = rhs.array.dup;
        return this;
    }
    ref Widget opAssign(Widget rhs)
    {
        swap(array, rhs.array);
        return this;
    }
}

void main()
{
    Widget w;
    w = Widget(50); // line 30
}

Two issues here:
1. Comment out the 2nd opAssign and the compiler should give an error, but it
doesn't.
(TDPL: // Cannot bind an rvalue of type Widget to ref Widget!)
2. TDPL's solution is 2 opAssigns, but this results in:

$ dmd -release -O -run test2.d 
test2.d(30): Error: overloads ref Widget(ref Widget rhs) and ref Widget(Widget
rhs) both match argument list for opAssign
test2.d(30): Error: function test2.Widget.opAssign called with argument types:
    ((Widget))
matches both:
    test2.Widget.opAssign(ref Widget rhs)
and:
    test2.Widget.opAssign(Widget rhs)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 15 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7513


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |DUPLICATE



10:59:44 PST ---
The issue is with struct literals being lvalues.

*** This issue has been marked as a duplicate of issue 9069 ***

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