1016 – CTFE fails with recursive functions

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1016 - CTFE fails with recursive functions
Summary: CTFE fails with recursive functions
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 All
: P2 normal
Assignee: Walter Bright
URL:
Keywords:
Depends on:
Blocks:
Reported: 2007年03月02日 04:53 UTC by Don
Modified: 2014年02月16日 15:26 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2007年03月02日 04:53:14 UTC
This seems to be a tail recursion problem? Calling the function recursively (while ignoring the result) seems to clobber the local value of the variable.
I'm not sure if line (3) is the same bug or not; there seems to be a morass of related bugs in the CTFE stuff.
-----------------
int exprLength(char [] s)
{
 int numParens=0;
 for (int i=0; i<s.length; ++i) {
 if (s[i]=='(') { numParens++; }
 if (s[i]==')') { numParens--; }
 if (numParens == 0) { return i; }
 }
}
char [] makePostfix(char [] operations)
{
 if (operations.length<2) return "x";
 int x = exprLength(operations);
 char [] first="bad";
 if (x>0) {
 first = "ok";
 char [] ignore = makePostfix(operations[1..x]); // This makes (2) fail.
 }
 return first;
}
void main()
{
 char [] q = makePostfix("(a+b)*c");
 assert(q=="ok"); // (1) PASSES
 const char [] q2 = makePostfix("(a+b)*c");
 static assert(q2=="ok"); // (2) FAILS
 static assert(makePostfix("(a+b)*c")=="ok"); // (3) not evaluatable at compile time
}
Comment 2 Thomas Kühne 2007年03月12日 01:23:34 UTC
Fixed in DMD-1.009


AltStyle によって変換されたページ (->オリジナル) /