Thread overview |
---|
March 02, 2007 [Issue 1016] New: CTFE fails with recursive functions | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=1016 Summary: CTFE fails with recursive functions Product: D Version: 1.007 Platform: PC OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: clugdbug@yahoo.com.au 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 } -- |
March 08, 2007 [Issue 1016] CTFE fails with recursive functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1016 thomas-dloop@kuehne.cn changed: What |Removed |Added ---------------------------------------------------------------------------- OS/Version|Windows |All ------- Comment #1 from thomas-dloop@kuehne.cn 2007-03-08 10:30 ------- Added to DStress as http://dstress.kuehne.cn/compile/c/const_43_A.d http://dstress.kuehne.cn/compile/c/const_43_B.d http://dstress.kuehne.cn/compile/c/const_43_C.d http://dstress.kuehne.cn/compile/c/const_43_D.d -- |
March 12, 2007 [Issue 1016] CTFE fails with recursive functions | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1016 thomas-dloop@kuehne.cn changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED ------- Comment #2 from thomas-dloop@kuehne.cn 2007-03-12 01:23 ------- Fixed in DMD-1.009 -- |
Copyright © 1999-2021 by the D Language Foundation