Bug 13601 – [REG2.064] static if (__ctfe) should emit error

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-10-10T21:17:00Z
Last change time
2015-02-18T03:38:42Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
ketmar

Attachments

IDFilenameSummaryContent-TypeSize
1445static_if_ctfe_warn.patchwarn on `static if (__ctfe)`text/plain2780

Comments

Comment #0 by ketmar — 2014-10-10T21:17:32Z
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 ----
Comment #4 by code — 2014-10-18T16:14:04Z
This commit https://github.com/D-Programming-Language/dmd/commit/021097056744c23231427b71e65bd04abc72d3e3 added a diagnostic regeression, making static if (__ctfe) print two errors. bug.d(3): Error: variable __ctfe forward referenced bug.d(3): Error: variable __ctfe cannot be read at compile time
Comment #5 by code — 2014-10-18T16:19:08Z
Comment #6 by code — 2014-10-18T19:04:14Z
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.
Comment #8 by k.hara.pg — 2014-10-23T02:16:40Z
Comment #9 by github-bugzilla — 2014-10-24T05:52:25Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/084a06583549525f7f7fa1c23bbd9164ce74e319 fix Issue 13601 - static if (__ctfe) should emit error https://github.com/D-Programming-Language/dmd/commit/ff8313c25377699be5ce61bcf21d51d352b45ad5 Merge pull request #4084 from 9rnsr/fix13601 [REG2.064] Issue 13601 - static if (__ctfe) should emit error
Comment #10 by github-bugzilla — 2015-02-18T03:38:42Z