shared and nonshared dtor

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jul 20 01:29:54 PDT 2014


On Sunday, 20 July 2014 at 02:57:44 UTC, Vlad Levenfeld wrote:
> I have a Resource struct that is supposed to free some memory 
> when it gets destroyed. Unfortunately, I can't define a 
> destructor. If I do, the compiler complains that it can't 
> destroy the shared versions. If I define a shared destructor, 
> the compiler complains that it can't disambiguate between 
> ~this() and shared ~this().

What you will probably need to do is to not try and use the same 
type as both shared and non-shared if it has a destructor. If 
it's going to be used as shared, then give it a shared destructor 
and make all of its other relevant functions shared. If it's 
going to be used as thread-local, then don't make any of it 
shared.

I would however suggest that you report this as a bug, since it 
really should be able to distinguish between shared and unshared 
destructors.

shared is a great concept, but we are going to need a few 
adjustments to its design in order to make it properly, fully 
useable.


More information about the Digitalmars-d-learn mailing list