pu$�le
Jonathan M Davis
jmdavisprog at gmail.com
Sun Jul 18 19:30:22 PDT 2010
On Sunday 18 July 2010 19:14:11 strtr wrote:
> I'm not sure whether you missed my point or are simple thinking out loud
> about unreachable code being a warning.
> My point was that the unreachable warning was wrong as there is no
> unreachable code.
Except that there _is_. You just can't see it. scope(X) creates a try-catch
block. So,
scope(exit) whatever;
/* code */
becomes
try
{
*/ code */
}
finally
{
whatever;
}
scope(success) whatever;
/* code */
becomes
/* code */
whatever;
scope(failure) whatever;
/* code */
becomes
try
{
/* code */
}
catch(Exception e)
{
whatever;
throw e;
}
So, something like
scope(failure) continue;
/* code */
becomes
try
{
/* code */
}
catch(Exception e)
{
continue;
throw e;
}
The throw statement is then unreachable. So, the warning is correct. The problem
is that it's not clear. Ideally, you would have a warning which specifically
mentions the fact that you can't do that sort of thing in a scope statement.
Unless the programmer is thinking about what exactly scope() becomes, the
unreachable statement warning will be confusing. So, that's a problem. It is,
however, correct. It probably merits its own bug report.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list