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.
Reduced test case shows this is very nasty bug in failing to restore local variable values after an indirect recursive call. ------------- void recurse6306() { bug6306(false); } bool bug6306(bool b) { int x = 0; if (b) recurse6306(); assert(x == 0); // fails!!!!! x = 1; return true; } static assert( bug6306(true) );
https://github.com/D-Programming-Language/dmd/commit/7ef3b2bb9e740df39108957ae5e3b2aa8253d351 https://github.com/D-Programming-Language/dmd/pull/284
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル