Destructor semantics
Jonathan M Davis
jmdavisprog at gmail.com
Tue Aug 10 16:58:08 PDT 2010
On Tuesday, August 10, 2010 16:15:33 foobar wrote:
> I agree :)
>
> In general, the rule is that destructors can only access value types. This
> can be enforced at compile time. Also, I was using structs and classes in
> my examples but this should be understood as value types vs. reference
> types.
>
> For example, when a dtor for a fixed-sized array is called (value type) it
> will in turn call dtors for its elements
If attempts to use any reference types in destructors were a compile-time error
with a clear error message, that could go a long way in stopping people from
trying to misuse destructors. As it is, there _are_ going to be plenty of D
programmers who write destructors which access references to GC-allocated data
and won't understand the weird bugs that they're getting.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list