Request for Comment assert(__ctfe)

Jonathan Marler johnnymarler at gmail.com
Wed Apr 8 19:16:15 UTC 2020


On Wednesday, 8 April 2020 at 09:48:25 UTC, Stefan Koch wrote:
> On Wednesday, 8 April 2020 at 09:11:45 UTC, Dennis wrote:
>> On Wednesday, 8 April 2020 at 08:42:52 UTC, Stefan Koch wrote:
>>> When existing the language is perfectly able to express (only 
>>> runs at ctfe).
>>
>> assert(__ctfe) does not express that you STATICALLY know it 
>> only runs at ctfe, it is a RUNTIME error and it is impossible 
>> to statically decide whether the function may actually get 
>> called outside ctfe context.
>
> The only reason why I used assert (__ctfe) not static assert 
> (__ctfe) is because that's impossible to express.
> since __ctfe is a magic runtime variable that's hardwired to be 
> zero in the non-ctfe case.

This may be a naive suggestion, but how hard would it be to make 
version(ctfe) work?

version (ctfe) string generateMixin(...) { ... }

Using version means you would be able to know earlier whether a 
function is ctfe-only, but I'm not sure how you could propogate 
that information through the rest of semantic-analysis and what 
effects that could have.



More information about the Digitalmars-d mailing list