Bug 5234 – [qtd] AA element assignment should use copy-constructor to initialize new elements
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2010-11-18T08:23:00Z
Last change time
2013-09-07T10:05:51Z
Assigned to
nobody
Creator
samukha
Comments
Comment #0 by samukha — 2010-11-18T08:23:00Z
Currently opAssign is called on newly created AA elements of struct types. This leaves us absolutely no possibility to properly initialize AA elements without introducing costly and unreliable checks in opAssign:
struct QString
{
ref QString opAssign(ref QString other)
{
if (memcmp(cast(void*)&this, cast(void*)&T.init, sizeof(this)) == 0)
{
// construct copy
}
else
{
// assign
}
}
}
QString[int] ss;
QString s = qs("some string");
ss[0] = s;
Can AA be modified so that new elements are initialized with the copy-constructor (as they should be) and not opAssign?
Comment #1 by samukha — 2010-11-18T08:37:19Z
T.init should be QString.init in the example
Comment #2 by k.hara.pg — 2013-09-07T10:05:51Z
*** This issue has been marked as a duplicate of issue 6178 ***