Solution to "statement is not reachable" depending on template variables?
Walter Bright via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Mar 31 18:21:32 PDT 2016
On 3/16/2016 4:18 AM, Johan Engelen wrote:
> I've found discussions, but not an actual "recommended" solution for the
> problem of "statement is not reachable" warnings in templates with early
> returns, e.g.:
> ```
> bool nobool(T...)() {
> foreach (i, U; T) {
> static if (is(U == bool)) {
> return false;
> }
> }
> return true; // emits "Warning: statement is not reachable"
> }
bool nobool(T...)() {
bool result = true;
foreach (i, U; T) {
static if (is(U == bool)) {
result = false;
break;
}
else
{
...
}
}
return result; // emits "Warning: statement is not reachable"
}
Note that the optimizer will remove the dead loads.
More information about the Digitalmars-d-learn
mailing list