[Issue 6306] New: [CTFE] Strange behavior of indirect recursive call in CTFE
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jul 13 02:11:21 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6306
Summary: [CTFE] Strange behavior of indirect recursive call in
CTFE
Product: D
Version: D2
Platform: x86
OS/Version: Windows
Status: NEW
Severity: critical
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: youxkei at gmail.com
--- Comment #0 from Hisayuki Mima <youxkei at gmail.com> 2011-07-13 02:06:02 PDT ---
void main(){}
struct Result{bool match; string value; string rest;}
Result paren(string input){
if(input[0] == '('){
input = input[1..$];
}else{
return Result(false, "", input);
}
string[] strs;
while(true){
Result r = function(string input){
Result r = paren(input);
if(r.match){
return r;
}
if(input[0] == ')'){
return Result(false, "", input);
}else{
return Result(true, input[0..1], input[1..$]);
}
}(input);
if(r.match){
strs = strs ~ r.value;
input = r.rest;
}else{
break;
}
}
if(input[0] == ')'){
input = input[1..$];
}else{
return Result(false, "", input);
}
string value = "(";
foreach(str; strs){
value = value ~ str;
}
value = value ~ ")";
return Result(true, value, input);
}
bool test(){//unittest
auto r = paren("((a))");
assert(r.match);
assert(r.rest == "");
assert(r.value == "((a))"); //assertion1
return true;
}
unittest{
static assert(test()); //line1
test();
}
This code cannot be compiled by dmd v2.054 because the assertion1, which is the
compile-time assertion, fails.
(Incidentally, r.value is "(a(a))" at assertion1.)
However, dmd v2.052 can compile this code well.
When I commented out the line 1, the code became able to be compiled dmd
v2.054 and the run-time unittest succeeded.
The function paren is a function which parses string in balanced-parentheses
and returns parsed string.
It has indirect recursive call or it calls a function which calls it.
When I rewrote the code as a code which has direct recursive call, the code the
code became able to be compiled dmd v2.054 and the run-time unittest succeeded,
too.
This is why I think indirect recursive call has strange behavior and it causes
the assertion1 to fail.
--
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