Summary: Warning for unreachable code in scope statements is
                    too confusing
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from Jonathan M Davis <> 2010-07-18 
19:53:09 PDT ---
Right now, if you compile the following code with -w (it compiles fine without

import std.stdio;

void someFuncWhichCanThrow(int val)
    throw new Exception("aaaaaaaa");

void main(string[] args)
    foreach(arg; args)
        scope(failure) continue;

you get the error

Warning: statement is not reachable

This will be highly confusing to many programmers. It _is_ technically correct
(there _is_ an unreachable statement), but not clear enough. It doesn't even
give a line number! If I understand correctly, what's happening is that the
foreach loop becomes this

    foreach(arg; args)
        catch(Exception e)
            throw e;

The throw statement is then unreachable (which is a warning and thus an error
with -w). However, since it's not in the programmer's code, the error gives no
line number. The statement which is unreachable isn't even in their code! A
better error is needed for this. Putting a statement in a scope statement which
will result in unreachable code should be a warning - if not an error - but it
needs to clearly indicate that the programmer is messing up with the scope
statement, not give a generic message about there being an unreachable

Actually, thinking about this a bit more, maybe

scope(failure) continue;

shouldn't be disallowed, since you may very well want to eat the exception and
continue. However, if that's the case, then -w shouldn't complain about
unreachable statements like it currently does with

scope(failure) continue;

So, either the warning needs to be fixed so that it's properly clear, or the
code generated by

scope(failure) flow-control-statement-of-some-kind;

needs to be fixed so that it doesn't have the throw in it anymore.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to