[Dlang-study] [lifetime] Few root decisions to take on RC classes
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Sat Oct 31 03:19:12 PDT 2015
On Saturday, October 31, 2015 03:10:41 Jakob Bornecrantz wrote:
> On Friday, 30 October 2015 at 21:31:56 UTC, Andrei Alexandrescu
> wrote:
> > A few matters Walter and I just discussed and wanted to submit
> > for scrutiny:
> >
> > * @rc classes shall not be single-rooted. Rationale: there is
> > no strong advantage in it and it would force all @rc classes to
> > embed a vptr. This has been already discussed and largely
> > agreed upon in this group.
>
> Have you done any investigation how this effects exception
> handling and
> dynamic upcasts?
Why would the existence (or lack thereof) of a root object affect either
exceptions or casting?
Unless Throwable becomes an @rc class (which might be a good idea),
exceptions won't be affected by @rc. And if Throwable does become an @rc
class, then Throwable would be the root of all exception classes, and the
lack of a general @rc class root would be irrelevant. As it is, exceptions
aren't treated as Objects under normal circumstances. The closest that they
get to to that would be when they're treated as an Exception or Throwable.
The same goes with casting. Having a root object is irrelevant to casting.
As long as the class reference that you're casting refers to an object whose
type is either the target type or a type derived from the target type, then
the cast will succeed. And if it doesn't, the result will be null. I don't
see how the existence of a root object would affect that.
Remember that C++ doesn't have a root object, and exceptions and casting
work just fine there.
- Jonathan M Davis
More information about the Dlang-study
mailing list