Bug 2282 – Struct copy-constructor should call opAssign

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-08-14T09:56:00Z
Last change time
2015-06-09T05:15:21Z
Assigned to
andrei
Creator
2korden

Comments

Comment #0 by 2korden — 2008-08-14T09:56:12Z
opAssign isn't called upon copy-construction. I think that the following: struct Test { void opAssign(Test other) { // ... } // ... } Test t1; Test t2 = t1; should be translated into the following: Test t1; Test t2 = void; t2 = t1;
Comment #1 by clugdbug — 2009-08-04T06:44:30Z
This behaviour is by design. I'm marking it as an enhancement, but it should probably be closed as invalid. It's definitely not a wrong-code bug.
Comment #2 by clugdbug — 2009-11-23T00:30:25Z
Invalid: use postblit instead. When the types are identical, this(this) gets called, not opAssign.
Comment #3 by 2korden — 2009-11-23T02:43:39Z
In D2, yes, but what about D1?
Comment #4 by clugdbug — 2009-11-23T03:00:24Z
(In reply to comment #3) > In D2, yes, but what about D1? The spec is quite clear: "The assignment operator cannot be overloaded for rvalues that can be implicitly cast to the lvalue type." (operatoroverloading.html#Assignment). And when I compile the initial code, I get a compiler error message which is clear and which is in perfect agreement with the spec: bug.d(19): Error: function test.Test.opAssign identity assignment operator ove rload is illegal
Comment #5 by 2korden — 2009-11-23T03:15:55Z
Great, thanks!