What does this compile-time error mean?

Jonathan M Davis jmdavisProg at gmx.com
Sun Feb 24 11:13:25 PST 2013


On Sunday, February 24, 2013 14:05:26 Timon Gehr wrote:
> On 02/24/2013 01:59 PM, Maxim Fomin wrote:
> > On Sunday, 24 February 2013 at 09:00:17 UTC, Jonathan M Davis wrote:
> >> Because main_cont is module-level variable, it must be initialized with a
> >> value at compile time. Classes can be used at compile time (at least
> >> some of
> >> the time), but they cannot stick around between compile time and runtime,
> >> meaning that you could potentially use them in a CTFE function, but
> >> you can't
> >> initialize a module-level or static variable (or enum) with them, and
> >> you're
> >> attempting to initialize maint_cont with a RedBlackTree, which is a
> >> class. It
> >> won't work.
> >> 
> >> - Jonathan M Davis
> > 
> > I would say that it is arbitrary restriction
> >
> >...
> 
> Yes, IIRC Don once stated that it is a problem with DMD's architecture.

Most restrictions in CTFE are a limitation of the current implementation 
rather than being something that's literally impossible to do (though some 
like the lack of source code aren't). In the case of a class, I believe that 
it would have to basically serialize the class at compile time and then 
deserialize it at runtime to do it. That's certainly possible to do in theory, 
but it's well beyond what the current CTFE implementation can do.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list