<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 7 December 2017 at 17:45, Nicholas Wilson via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On Friday, 8 December 2017 at 01:30:13 UTC, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I tried this, and was surprised it didn't work:<br>
<br>
int ctfeOnly(int x)<br>
{<br>
static assert(__ctfe);<br>
return x + 1;<br>
}<br>
<br>
This would probably solve the problem in a satisfying way without an attribute?<br>
</blockquote>
<br></span>
I think that's because __ctfe, despite being magic, is actually a regular variable.<br>
<br>
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<br>
<br>
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.<br>
</blockquote></div><br></div><div class="gmail_extra">Oh, sorry, I forgot key detail! (parens)</div><div class="gmail_extra"><br></div><div class="gmail_extra">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(?))<br></div></div>