[GSoC] Pass-by-value opAssign called with a ref doesn't call postblit, possible bug.
Cristi Cobzarenco
cristi.cobzarenco at gmail.com
Thu Jun 23 10:37:13 PDT 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20110623/8aa7391c/attachment-0001.html>
More information about the Digitalmars-d
mailing list