Solution to "statement is not reachable" depending on template variables?
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Mar 17 10:12:07 PDT 2016
On 3/16/16 9:48 PM, tsbockman wrote:
> On Wednesday, 16 March 2016 at 11:22:02 UTC, rikki cattermole wrote:
>> Change those static if's to just plain old ifs.
>
> This only works (sometimes) because D's value range propagation doesn't
> understand comparisons or normal if statements very well. This will
> hopefully be fixed sooner or later:
> https://github.com/D-Programming-Language/dmd/pull/1913
> https://github.com/D-Programming-Language/dmd/pull/5229
>
> The only future-proof way to fix the "statement is not reachable"
> warning, is to guard the potentially unreachable code with a `static if`
> whose predicate precisely describes the circumstances in which it
> becomes unreachable...
>
> ....Which itself is a terrible solution that doesn't scale well at all
> to complex generic code and violates the "DRY" principle.
>
> We really ought to just remove the warning. It just doesn't mesh well
> with D's super-powered meta-programming features.
Yes. I agree. The way I look at it is that the code *is* reached in some
cases, so it should compile (and just remove that section in that instance).
IMO any time a template value is used for branching, it should turn that
warning off.
-Steve
More information about the Digitalmars-d-learn
mailing list