Disabling struct destructor illegal?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Thu Jul 19 12:46:57 UTC 2018


On Thursday, July 19, 2018 10:04:34 RazvanN via Digitalmars-d-learn wrote:
> I just don't understand why you would ever mark the destructor of
> a struct with @disable. When is that useful? If it's not, why not
> just forbit it?

There's nothing special about destructors here. You can @disable any member
function, and if you do, you get an error if you try to use it, since it's
@disabled. So, code that doesn't use an @disabled function works just fine,
and any code that attempts to use it gets an error. For the vast majority of
functions, @disabling them really doesn't make any sense, but from what I
can tell, @disable was simply implemented as a general feature rather than
trying to allow specific functions to be @disabled and then have to add code
for each function that we want to be able to @disable. So, the fact that you
can @disable destructors is just the result of the feature being implemented
in a simple, straightforward manner. But while I agree that @disabling
destructors doesn't make sense, I don't see why it would actually be a
problem that it's allowed. Anyone who tries it is just going to quickly get
errors and have to remove @disable from the destructor. Explicitly make it
illegal to mark a destructor with @disabled doesn't really add anything from
what I can see.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list