Uh... destructors?

%u wfunction at hotmail.com
Mon Feb 21 22:08:38 PST 2011


> dmd is pretty lax about attributes which don't apply. It generally just ignores them. Personally,
I think that it should error on invalid attributes, but for some reason, that's not how it works.
Of course, there could be other bugs in play here, but there's every possibility that the end
result is completely valid.

Well, the trouble is, pretty much all of these are invalid attributes:
- const and pure make no sense, since destructors (should) change an object's state
- override and final make no sense, since destructors obviously aren't ever overridden... they're
always called after the subclass's destructor is called
- static obviously makes no sense
- synchronized is meaningless since there's only one thread ever running the destructor anyway
- private makes no sense since (unless we're trying to imitate C++ here) destructors are only
called from the runtime, and nowhere else.
- The only meaningful attribute there is extern(C).

I would agree that DMD should ignore the attributes that are redundant or optional (e.g. it should
be okay for "static" to be written and/or omitted at the module-level, and DMD should ignore it)
but I don't see why _wrong_ attributes should be ignored... it confuses the programmer, opens the
potential for error, and doesn't have any benefits. (The only exception I can think of to this rule
would be attributes that cannot be removed, like saying "private:" in the beginning... for general
attributes like those, I guess DMD can ignore them, but for specifically written attributes like
these, is there any benefit whatsoever to allowing them?)

Thanks!


More information about the Digitalmars-d mailing list