Bug 5826 – Error: Statement SwitchErrorStatement::toCBuffer() cannot be interpreted at compile time

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-04-09T12:20:00Z
Last change time
2015-06-09T05:10:38Z
Keywords
diagnostic
Assigned to
nobody
Creator
ibuclaw

Comments

Comment #0 by ibuclaw — 2011-04-09T12:20:08Z
From fail_compilation/fail146.d: int bar(int i) { switch (i) { case 1: i = 4; break; case 8: i = 3; break; } return i; } void main() { static b = bar(7); printf("b = %d, %d\n", b, bar(7)); assert(b == 3); } Error message: fail_compilation/fail146.d(4): Error: no default or case for 7 in switch statement fail_compilation/fail146.d(4): Error: Statement SwitchErrorStatement::toCBuffer() cannot be interpreted at compile time fail_compilation/fail146.d(18): Error: cannot evaluate bar(7) at compile time fail_compilation/fail146.d(18): Error: cannot evaluate bar(7) at compile time fail_compilation/fail146.d(19): Error: 'printf' is not defined, perhaps you need to import core.stdc.stdio; ? For all intent and purposes, this line: fail_compilation/fail146.d(4): Error: Statement SwitchErrorStatement::toCBuffer() cannot be interpreted at compile time Should ideally not be emitted as an error. Regards
Comment #1 by ibuclaw — 2012-08-29T12:46:22Z
(In reply to comment #0) > From fail_compilation/fail146.d: > > int bar(int i) > { > switch (i) > { > case 1: > i = 4; > break; > case 8: > i = 3; > break; > } > return i; > } > > void main() > { > static b = bar(7); > printf("b = %d, %d\n", b, bar(7)); > assert(b == 3); > } > > > > Error message: > fail_compilation/fail146.d(4): Error: no default or case for 7 in switch > statement > fail_compilation/fail146.d(4): Error: Statement > SwitchErrorStatement::toCBuffer() > cannot be interpreted at compile time > fail_compilation/fail146.d(18): Error: cannot evaluate bar(7) at compile time > fail_compilation/fail146.d(18): Error: cannot evaluate bar(7) at compile time > fail_compilation/fail146.d(19): Error: 'printf' is not defined, perhaps you > need to import core.stdc.stdio; ? > > > For all intent and purposes, this line: > > fail_compilation/fail146.d(4): Error: Statement > SwitchErrorStatement::toCBuffer() cannot be interpreted at compile time > > Should ideally not be emitted as an error. > > Regards Error message is now: test.d:3: Error: non-final switch statement without a default is deprecated test.d:17: Error: CTFE failed because of previous errors in bar test.d:18: Error: 'printf' is not defined, perhaps you need to import core.stdc.stdio; ? Interestingly, fail146.d has been removed from the testsuite, why is this? Marking as resolved anyway...
Comment #2 by braddr — 2012-08-30T15:39:17Z
I was curious, so I went to find the reason: https://github.com/D-Programming-Language/dmd/commit/d530bf60e34bb01932d5656c6a1b392beac6e5d2 Found via looking at the history for the file: https://github.com/D-Programming-Language/dmd/commits/master/test/fail_compilation/fail146.d also doable through the git cli: git log test/fail_compilation/fail146.d