When the following is compiled with -w or -wi, it will give a warning without a line number ---- bool addArticle() { scope(failure) return false; return true; } ---- Tested on dmd 2.057 on OS X 64 and Ubuntu 32. $ dmd -w test.d Warning: statement is not reachable
https://github.com/D-Programming-Language/dmd/pull/610 In addArticle function, dmd translates the body code like follows: try { return true; } catch (Throwable __o) { return false; throw __o; // #1 rethrow catched exception object } The "statement is not reachable" warning is caused by line #1. After my patch, the translation result would change like follows: try { return true; } catch (Throwable __o) { return false; // this statement never fall through next. // so next unreachable rethrowing is implicitly removed. } Finally, original warning would never be generated.
Technical note: Maybe, the original issue by Robert Clipsham is "unreachable scope(failure) should warn "statement is not reachable" _with line number_. But today it is technically enhancement. Because: 1. Current D2 dmd does only check Exception throwing possibilities in flow analysis. That means Throwable is not the target of the analysis. In above code, scope(failure) return false; return true; // (a) dmd does not consider the statement (a) throws Throwable or not. 2. scope(failure) catches Throwable object and rethrow it. Therefore the scope(failure) statement is always analysed as *may be reachable*. From the two reasons, current dmd cannot detect that the `scope(failure) return false;` is not reachable.
Posted bug 7240 as an enhancement.
https://github.com/D-Programming-Language/dmd/commit/458065293bd4cf990fb99bcd01fc294e7df21c17 https://github.com/D-Programming-Language/dmd/commit/986404479ea9eac7a9caa32be1f92c22a8aee38a
There's a missing line number with -w here also (recent dmd): import std.stdio; void f() { throw new Exception("msg"); scope(exit) write("5"); scope(success) write("6"); }
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル