[Issue 8714] New: Instantiate template within CTFE with same CTFE returned value
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Sep 23 14:07:33 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8714
Summary: Instantiate template within CTFE with same CTFE
returned value
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: jens.k.mueller at gmx.de
--- Comment #0 from jens.k.mueller at gmx.de 2012-09-23 14:08:29 PDT ---
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/mailman.148.1348176167.5162.digitalmars-d@puremagic.com
http://forum.dlang.org/thread/20120920212236.GD3056@minet.uni-jena.de
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list