[Issue 6581] Yet another dtor/postblit problem?
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Sep 20 07:07:46 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6581
--- Comment #3 from Kenji Hara <k.hara.pg at gmail.com> 2011-09-20 07:07:18 PDT ---
(In reply to comment #2)
> It might be more complicated then I thought, postblits of members do work.
> I'd better leave the cause of problem to thouse in the know. Another variation
> of test:
I think this is right behavior, and no problem.
Please note this line:
> a = A(dummy); // a(dummy) was a typo, thought it changes nothing
This is "assignment", not initializing.
The assignment of an object that has postblit (like A) is implemented *swap and
destroy*. For this purpose, D compiler implements opAssign implicitly, like
follows:
struct A {
...
ref A opAssign(A rhs) { // rhs is copyed from original value
std.algorithm.swap(this, rhs); // bitwise swapping
return rhs;
// rhs is equals to original 'this', and it is destroyed here.
}
}
Therefore, the assignment of an object of A always increment A.dtor.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list