www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [GSoC] Pass-by-value opAssign called with a ref doesn't call

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" );
 return 0;


Before assignment
After assignment

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