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;
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.
Invalid: use postblit instead. When the types are identical, this(this) gets called, not opAssign.
In D2, yes, but what about D1?
(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
Great, thanks!