Bug in RefCounted?

Rene Zwanenburg renezwanenburg at gmail.com
Sun Oct 27 14:02:00 PDT 2013


On Thursday, 24 October 2013 at 16:46:37 UTC, Ali Çehreli wrote:
> Technically, it is a problem with FooWrapper. Regardless of 
> whether RefCounted's behavior, by default, structs in D are 
> freely copyable and movable value types. The compiler can do 
> those things as it sees fit.
>
> Since FooWrapper owns a resource, it must also define the 
> post-blit to make a copy of Foo.
>
> (As an aside, dmd at git head does not make such a copy.)
>
> Ali

Thanks, that's indeed an oversight on my part. Still, I think 
there's something strange going on.

The problem is that the FooWrapper destructor is called twice, 
one time with a garbage foo pointer. The example prints:
Destroying Foo 40CED748
Destroying Foo 4002DFF0
There is only one Foo instance created. A null pointer would make 
sense, but where's that second pointer coming from?


More information about the Digitalmars-d-learn mailing list