[Issue 2423] New: Erroneous unreachable statement warning

Lars Ivar Igesund larsivar at igesund.net
Mon Oct 20 01:20:17 PDT 2008


Lars Ivar Igesund wrote:

> Don wrote:
> 
>> d-bugmail at puremagic.com wrote:
>>> http://d.puremagic.com/issues/show_bug.cgi?id=2423
>>> 
>>>            Summary: Erroneous unreachable statement warning
>>>            Product: D
>>>            Version: 1.035
>>>           Platform: Other
>>>         OS/Version: All
>>>             Status: NEW
>>>           Keywords: diagnostic
>>>           Severity: regression
>>>           Priority: P2
>>>          Component: DMD
>>>         AssignedTo: bugzilla at digitalmars.com
>>>         ReportedBy: larsivar at igesund.net
>>> 
>>> 
>>> Consider the following function:
>>> 
>>> void foo() {
>>> 
>>>     do {
>>>         if (false)
>>>             return 1;
>>>     } while (true);
>>> }
>>> 
>>> Compiling with -w, results in
>>> 
>>> warning - whiletrue.d(6): Error: statement is not reachable
>>> 
>>> Minimized from a module in Tango, meaning Tango does not compile with
>>> warnings on.
>>> 
>>> This regression was introduced in DMD 1.032.
>>> 
>>> 
>> Why is that wrong? "return 1" looks unreachable to me.
> 
> It is
> 
> while(true)
> 
> that is line 6 (you can move the while a few lines down to see that it
> isn't just a line number error). The return makes the statement on that
> line ("true" I assume) unreachable, which is correct without the
> conditional. So it is the presence of the if (false) that makes this an
> error.
> 

Of course, any conditional should remove this warning - in the module
(tango/io/vfs/ZipFolder.d) where I found this problem, the return is in the
else block.

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource, #d.tango & #D: larsivi
Dancing the Tango


More information about the Digitalmars-d-bugs mailing list