[Issue 9732] Do not call opAssign() for the first assignment to member in the constructor
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Mar 17 09:22:00 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9732
--- Comment #7 from Maxim Fomin <maxim at maxim-fomin.ru> 2013-03-17 09:21:59 PDT ---
(In reply to comment #3)
> I really don't think that's a problem. If anything, the default value should
> NOT be destroyed in the constructor. After all, it hasn't really even been
> initialized yet.
There are several corner cases when dtor gets default value. By the way, how
you can distinguish whether object was recently initialized to its state was
reseted?
> If anything, that's exactly how "aggregate construction" works: postblit each
> value over the current fields, but DON'T destroy the fields:
>
> //--------
> import std.stdio;
>
> struct Inner
> {
> int i;
> this(this){} //Postblit implies destruction of this.
> ~this()
> {
> writeln(i);
> }
> }
>
> struct Outer
> {
> Inner inner = Inner(1); // <-- compile-time .init
> }
>
> void main()
> {
> auto inner = Inner(2);
> {
> writeln("****");
> auto outer = Outer(inner); // Overwrite with postblit, but don't call
> destructor.
> writeln("****");
> }
> {
> writeln("****");
> auto outer = Outer(inner); // Overwrite with postblit, but don't call
> destructor.
> outer.inner = inner; // Call postblit, destroying previous state.
> writeln("****");
> }
> }
> //--------
> ****
> **** //Notice no destroyer called here
> 2 //This is outer's destroyer destroying its inner
> ****
> 2 //This is our second blit.
> ****
> 2 //This is out second outer destroyer's destroying its inner
> 2 //This is our inner's destroyer
> //--------
>
> So yeah, my conclusion is: destroyers are not a problem to this proposal.
I don't how this is related to the issue.
--
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