On 7 December 2017 at 17:45, Nicholas Wilson via Digitalmars-d <
digitalmars-d@puremagic.com> wrote:

> On Friday, 8 December 2017 at 01:30:13 UTC, Manu wrote:
>
>> I tried this, and was surprised it didn't work:
>>
>> int ctfeOnly(int x)
>> {
>> static assert(__ctfe);
>> return x + 1;
>> }
>>
>> This would probably solve the problem in a satisfying way without an
>> attribute?
>>
>
> I think that's because __ctfe, despite being magic, is actually a regular
> variable.
>
> While this looks not too inelegant for a user perspective, I dont know how
> to handle this from a compiler perspective: filtering by attribute is as
> easy as "does this function have a UDA ctfeonly? If so, don't code generate
> it. Generating errors at codegen time is also trivial: when generating a
> call check to see if the callee is @ctfeonly, if it is give an error message
>
> I don't know how to do that for a `static assert(__ctfe);`. That would
> require changes and semantic analysis in the front end which I am much less
> familiar with.
>

Oh, sorry, I forgot key detail! (parens)

int ctfeOnly()(int x) ...  (in my mind, it was a template function, which
means it would instantiate for the ctfe call separately to regular calls(?))

Reply via email to