www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Statement is unreachable error

reply "deadalnix" <deadalnix gmail.com> writes:
I reach this error all the time. When debugging for instance, I 
may want to stick a throw in the middle of some code, or 
whatever, and get into it, have to go back to the code, comment 
bunch of stuff, go back to compile.

This is something that is obviously important to have, but I 
think to have it by default is really annoying.

In addition, it tends to kick in when using static if. See sample 
code below :

uint foo() {
     static if(condition) {
         return 0;
     }

     // Do some computation.
     return value;
}

Now, if you want that piece of code to compile, you got to stick 
the whole function body into an else, and it really make the code 
unreadable sometime when you got static ifs within other static 
ifs.

Can we at least disable the feature for termination of control 
flow that belongs to different compile time scope ?
Jun 03 2013
next sibling parent "Andrej Mitrovic" <andrej.mitrovich gmail.com> writes:
On Monday, 3 June 2013 at 14:53:23 UTC, deadalnix wrote:
 I reach this error all the time. When debugging for instance, I 
 may want to stick a throw in the middle of some code

I have the same problem, sometimes for testing purposes (exactly for debugging) I'd like to return early or throw, but then I get compiler errors.
Jun 03 2013
prev sibling next sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Monday, 3 June 2013 at 14:57:13 UTC, Andrej Mitrovic wrote:
 On Monday, 3 June 2013 at 14:53:23 UTC, deadalnix wrote:
 I reach this error all the time. When debugging for instance, 
 I may want to stick a throw in the middle of some code

I have the same problem, sometimes for testing purposes (exactly for debugging) I'd like to return early or throw, but then I get compiler errors.

It would be nice to have a compiler switch that turns off these errors.
Jun 03 2013
prev sibling parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Monday, 3 June 2013 at 15:21:15 UTC, John Colvin wrote:
 On Monday, 3 June 2013 at 14:57:13 UTC, Andrej Mitrovic wrote:
 On Monday, 3 June 2013 at 14:53:23 UTC, deadalnix wrote:
 I reach this error all the time. When debugging for instance, 
 I may want to stick a throw in the middle of some code

I have the same problem, sometimes for testing purposes (exactly for debugging) I'd like to return early or throw, but then I get compiler errors.

It would be nice to have a compiler switch that turns off these errors.

One of the problem's _I_ have been able to observe, and which is particularly problematic (IMO), is when it happens only in release. For example: foreach(e; range) if(e==1) return 1; return 0; Imagine now "range" happens to be an infinite range. Now, return 0 will never be reached. Unfortunately, the compiler only sees this in release. This makes unittesting problematic, since there have been a few observed cases of unittests that passed, but would have failed to compile in a production environment.
Jun 03 2013