digitalmars.D - [GSoC] Pass-by-value opAssign called with a ref doesn't call
- Cristi Cobzarenco (35/35) Jun 23 2011 ------------------------------
------------------------------ import std.stdio; struct Test { this( this ) { writeln( "Test.this(this)" ); } ~this() { writeln( "Test.~this()" ); } void opAssign( Test rhs ) { writeln( "Test.opAssign" ); } } ref Test makeRef( ref Test test ) { return test; } int main(string[] argv) { Test x,y; writeln( "Before assignment" ); x = makeRef(y); writeln( "After assignment" ); readln(); return 0; } ------------------------------ Output: Before assignment Test.opAssign Test.~this() After assignment Test.~this() Test.~this() ------------------------------ The code above assigns a reference to a Test object to another Test object. The assignment doesn't call the postblit constructor, yet it calls the destructor (lines 2,3 in the output). Changing the assignment to "x = y;" makes it call the postblit. Is this correct behaviour, or should I file it as a bug? --- Cristi Cobzarenco BSc in Artificial Intelligence and Computer Science University of Edinburgh Profile: http://www.google.com/profiles/cristi.cobzarenco
Jun 23 2011