digitalmars.D.bugs - [Issue 14835] New: Statement is not reachable doesn't play along
- via Digitalmars-d-bugs (47/47) Jul 26 2015 https://issues.dlang.org/show_bug.cgi?id=14835
https://issues.dlang.org/show_bug.cgi?id=14835 Issue ID: 14835 Summary: Statement is not reachable doesn't play along generic code Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: pro.mathias.lang gmail.com The "statement is not reachable" warning is a major annoyance when writting generic code. It often end up being more of a disturbance than an actual help. The reason is that it doesn't accept code that would be common at runtime. Consider the following example: ```` bool isEven(int i) { if (i % 2) return true; return false; } ```` In normal code, requiring `return false;` to be in an `else` branch would be a major annoyance for no benefit. Now take the exact same code, but at CT: ```` bool isEven(int i)() { static if (i % 2) // static or not, the warning will get triggered if i is even return true; return false; } ```` This is a simple example, but I believe it illustrate the problem well enough. In addition to the "put everything in a branch" problem, there are some cases where it simply forces you to move to recursion everywhere because there's no way to fix the warning, for example: https://github.com/rejectedsoftware/vibe.d/blob/38784138ad8cc8f442bd0e76a1b740040ff33fe5/source/vibe/internal/meta/typetuple.d#L101-L121 This code can only be fixed in 2 ways: either move to recursion, or use a dummy boolean parameter to confuse DMD's flow analysis (example: https://github.com/rejectedsoftware/vibe.d/blob/38784138ad8cc8f442bd0e76a1b740040ff33fe5/source/vibe/web/rest.d#L1150-L1154 ). --
Jul 26 2015