Bug 1016 – CTFE fails with recursive functions

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
All
Creation time
2007-03-02T04:53:00Z
Last change time
2014-02-16T15:26:25Z
Assigned to
bugzilla
Creator
clugdbug

Comments

Comment #0 by clugdbug — 2007-03-02T04:53:14Z
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 #1 by thomas-dloop — 2007-03-08T10:30:10Z
Comment #2 by thomas-dloop — 2007-03-12T01:23:34Z
Fixed in DMD-1.009