Bug 8714 – Missing error message with circular use of CTFE

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-23T14:08:00Z
Last change time
2015-06-09T05:11:51Z
Keywords
CTFE, diagnostic, pull
Assigned to
nobody
Creator
jens.k.mueller

Comments

Comment #0 by jens.k.mueller — 2012-09-23T14:08:29Z
To better integrate CTFE and templates it may be worthwhile to allow code as follows string foo(string f) { if (f == "somestring") { return "got somestring"; } return bar!(foo("somestring")); } template bar(string s) { enum bar = s; } Note, that the return value of foo("somestring") is "got somestring" which should be possible to pass to some template. Code like string foo(string f) { if (f == "somestring") { return "got somestring"; } return bar!(foo("somestring"))(); } string bar(string s)() { return s; } should compile as well. Both fail with dmd 2.060. The first code fails with: test.d(7): called from here: foo("somestring") test.d(7): called from here: foo("somestring") test.d(7): called from here: foo("somestring") test.d(7): Error: expression foo("somestring") is not a valid template value argument test.d(12): called from here: foo("somestring") test.d(12): called from here: foo("somestring") test.d(7): Error: template instance test.bar!(foo("somestring")) error instantiating and the second with: test.d(7): called from here: foo("somestring") test.d(7): called from here: foo("somestring") test.d(7): called from here: foo("somestring") test.d(7): Error: expression foo("somestring") is not a valid template value argument test.d(7): Error: template instance test.bar!(foo("somestring")) error instantiating If code like above should stay invalid the compiler diagnostics should be improved. I.e. recursive dependency on foo when analyzing foo in CTFE. See also the discussion on the list http://forum.dlang.org/thread/[email protected] http://forum.dlang.org/thread/[email protected]
Comment #1 by clugdbug — 2012-09-24T23:39:16Z
Original title: Instantiate template within CTFE with same CTFE returned value The 'enhancement request' part of this bug is the same as bug 8713. Changing this to a diagnostic bug. https://github.com/D-Programming-Language/dmd/pull/1141
Comment #2 by github-bugzilla — 2012-10-09T22:33:00Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/4eb179d96c4b3402250a707e29ca00ca982cd431 Fix issue 8714 Missing error message with circular use of CTFE The error message was missing, and the supplementary error was also spuriously repeated. https://github.com/D-Programming-Language/dmd/commit/649ad799371e282391813ba9126f5f63f4223656 Merge pull request #1141 from donc/ctfe8714recursive_semantic Fix issue 8714 Missing error message with circular use of CTFE
Comment #3 by yebblies — 2012-10-09T22:34:37Z
Fixed for D2