Statement is unreachable error

monarch_dodra monarchdodra at gmail.com
Mon Jun 3 22:13:05 PDT 2013


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.


More information about the Digitalmars-d mailing list