www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9907] New: Struct literal with destructor should match to non-ref overload

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

           Summary: Struct literal with destructor should match to non-ref
                    overload
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: k.hara.pg gmail.com



From the forum discussion:
http://forum.dlang.org/thread/kjv4ae$3hp$1 digitalmars.com

This code should call void opAssign(S rhs) twice.

import std.stdio;
import std.string;

version = destructor_defined;

struct S
{
    int i;

    string info() const
    {
        return format("%s(%s)", &i, i);
    }

    void opAssign(S rhs)
    {
        writefln("%s from Rvalue %s", this.info(), rhs.info());
    }

    void opAssign(ref S rhs)
    {
        writefln("%s from Lvalue %s", this.info(), rhs.info());
    }

    version (destructor_defined)
    {
        ~this()
        {
            writefln("destroying %s", this.info());
        }
    }
}

S foo(int i)
{
    return S(i);
}

void main()
{
    auto s = S(1);

    // Assignment from two kinds of rvalues
    s = foo(2);  // [1]
    s = S(3);    // [2]
}

In [1], void opAssign(S rhs) is called correctly.
But in [2], void opAssign(ref S rhs) is wrongly called.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 08 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9907


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull



https://github.com/D-Programming-Language/dmd/pull/1873

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 08 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9907




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/065514be2bc214f70575e2877f971da11a3d8637
fix Issue 9907 - Struct literal with destructor should match to non-ref
overload

https://github.com/D-Programming-Language/dmd/commit/e5ca01905d59fbbccce45ef66803ee8f05a2ef70


Issue 9907 - Struct literal with destructor should match to non-ref overload

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 17 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9907


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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