Compilable Recursive Data Structure ( was: Recursive data structure using template won't compile)

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Thu Nov 8 15:05:23 PST 2012


On Thu, 08 Nov 2012 23:28:05 +0100
"Rob T" <rob at ucora.com> wrote:
> 
> It could be that the template system simply does not operate as 
> we expect, which IMO would be unfortunate because it will 
> describe a system somewhat unrelated to actual coding (a problem 
> C++ templates are infamous for), or that it is a manifestation of 
> the problem where the out-of-order instantiations are not being 
> evaluated in a way that works for all *legal* cases, which in 
> that case can be considered a bug, esp since D is supposed to 
> allow for out-of-order definitions.
> 

Historically, DMD tended to have a lot of trouble actually resolving
forward references according to spec (perhaps due to it's C/C++ roots?).
Most of big glaring problems have been fixed since then, but
unfortunately there's still a number of edge cases yet to be ironed out.

It *is* possible to construct types in a way that is inherently
ambiguous, and cannot be correctly handled by the compiler even
in theory. So naturally those cases will end up being "forward
reference", or perhaps more accurately "circular definition". But your
example is definitely not such a case, so however the compiler is
currently processing it, it needs to be fixed.

FWIW, you should be able to work around the issue by making some of the
pointers "void*". You'll lose some type safety and have to remember to
cast things correctly, but it should at least make it compile (although
I haven't tried it).



More information about the Digitalmars-d-learn mailing list