Created attachment 1445
warn on `static if (__ctfe)`
there is no much sense in doing `static if (__ctfe) …`, and this is common mistake. even seasoned D developers aren't prone to it. so i think that compiler should warn us about it. i wrote somewhat hacky but working code for this.
Comment #1 by public — 2014-10-11T03:50:32Z
Any DMD changes need relevant test cases added
Comment #2 by ketmar — 2014-10-11T08:06:48Z
that's only if the author wants to go to mainline. me not. i don't care anymore if my code will lang into the oficial branch or not. it's just a patch for those who interested to patch dmd manually and either trust me or will write test themselves.
Comment #3 by code — 2014-10-18T15:53:06Z
This worked as expected 2.063.2.
cat > bug.d << CODE
void foo()
{
static if (__ctfe) {}
}
CODE
dmd -c bug
----
bug.d(3): Error: variable __ctfe cannot be read at compile time
----
Mmh, this happens because the static if expression is now handled by CTFE instead of constant folding.
CTFE would need to look at the scope flags to check whether __ctfe can be read.
Comment #7 by ketmar — 2014-10-22T18:36:32Z
sorry for the noise, it seems that i was unintentionally offensive once again in comment #2. what i really wanted to say is that "my patch is in no way ready to go to official repository, it's just a crude hack. use it on your own risk and only if you want to have some diagnostics right away without waiting until someone will write a proper patch".
i'm sorry.