Fixing the issue with "Statement unreachable"

Mathias LANG geod24 at gmail.com
Mon Apr 27 05:10:56 UTC 2020


On Monday, 27 April 2020 at 03:59:57 UTC, Steven Schveighoffer 
wrote:
> Is there a way we can fix this?
>
> [...]
>
> Would there be a way to say "if this part of the code is 
> reachable, then include the following"?
>
> (NOTE: I know I could switch all the "return true" to return 
> the result of the functions, but the real code is more complex 
> and not simple boolean calls)
>
> -Steve

Personally when I can't find any satisfactory solution, I just 
add `bool hack` at the top and an `if (!hack)`. The backend / 
inliner might be smart enough to optimize it, but it's enough to 
shut the frontend up.
This is essentially 
https://issues.dlang.org/show_bug.cgi?id=14835 .
As you can see, Andrei proposed to insert an `else` if there's a 
static if. I'm personally not fan of this, I just think we should 
fix DMD frontend to stop emitting useless warnings.


More information about the Digitalmars-d mailing list