www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14835] New: Statement is not reachable doesn't play along


          Issue ID: 14835
           Summary: Statement is not reachable doesn't play along generic
           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
     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:

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:

Jul 26 2015