D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9907 - Struct literal with destructor should match to non-ref overload
Summary: Struct literal with destructor should match to non-ref overload
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords: pull, wrong-code
Depends on:
Blocks:
 
Reported: 2013-04-08 19:10 UTC by Kenji Hara
Modified: 2013-04-17 23:00 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kenji Hara 2013-04-08 19:10:38 UTC
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.
Comment 2 github-bugzilla 2013-04-17 14:08:04 UTC
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
Merge pull request #1873 from 9rnsr/fix9907

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