@ctfeonly
Nicholas Wilson
iamthewilsonator at hotmail.com
Fri Dec 8 01:45:16 UTC 2017
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.
More information about the Digitalmars-d
mailing list