D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7240 - Possibilities of throwing Throwable should be calculated
Summary: Possibilities of throwing Throwable should be calculated
Status: RESOLVED LATER
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-06 09:20 UTC by Kenji Hara
Modified: 2021-01-24 06:43 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kenji Hara 2012-01-06 09:20:03 UTC
(This issue is derived from bug 7232)

In following code, statement #1 throws no exception, so #2 is never reachable.
But current dmd cannot detect it, 

bool addArticle()
{
    scope(failure) return false;  // #2
    return true;   // #1
}

My technical note from http://d.puremagic.com/issues/show_bug.cgi?id=7232#c2
>
> Maybe, the original issue by Robert Clipsham is "unreachable scope(failure)
> should warn "statement is not reachable" _with line number_.
> But today it is technically enhancement. Because:
> 
> 1. Current D2 dmd does only check Exception throwing possibilities in flow
> analysis.
> That means Throwable is not the target of the analysis. In above code,
> 
>     scope(failure) return false;
>     return true;    // (a)
> 
> dmd does not consider the statement (a) throws Throwable or not.
> 
> 2. scope(failure) catches Throwable object and rethrow it. Therefore the
> scope(failure) statement is always analysed as *may be reachable*.
> 
> From the two reasons, current dmd cannot detect that the `scope(failure) return
> false;` is not reachable.

I think dmd should also calculate the Throwable flow, not only the Exception flow (it is related to 'nothrow' attribute).