Bug 9907 – Struct literal with destructor should match to non-ref overload
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-04-08T19:10:00Z
Last change time
2013-04-17T23:00:44Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2013-04-08T19:10:38Z
From the forum discussion:
http://forum.dlang.org/thread/[email protected]
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.