Am Tue, 30 Aug 2016 08:57:25 +0200
schrieb Jacob Carlborg <>:

> On 2016-08-29 10:39, Stefan Koch wrote:
> > Thanks guys.
> >
> > I just came up with a nifty little patch that makes it possible to
> > ensure that a function is _only_ used at ctfe.
> > Or the opposite.
> >
> > static assert(__ctfe, "This function is not supposed to be called
> > outside of ctfe");
> > and static assert(!__ctfe, "This function is not supposed to be
> > called during ctfe");
> >
> > similarly you can use static if (__ctfe).
> >
> > Is it worth trying to get it into master ?  
> Wow, absolutely :)

There are some nice use cases for this:
* Do not enforce @nogc for CTFE only functions, so you can mark a
  complete module nogc: and CTFE only functions will get ignored
* Do not emit code for CTFE only functions. This is useful for bare
  metal programming: The CTFE only function can depend on druntime
  functions not available in the bare metal runtime.

These are common problems when using string mixins: The functions
to generate the mixed in code use string manipulation which is usually
not @nogc and might require runtime functions. But the code generation
function is exclusively used in CTFE.

Reply via email to