[Issue 14835] Statement is not reachable doesn't play along generic code

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Oct 13 13:23:56 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14835

--- Comment #4 from Steven Schveighoffer <schveiguy at yahoo.com> ---
What the compiler is doing here is giving you information that code you wrote
will not get executed.

The problem is that the code in question is only one *particular* execution (or
instantiation) of that code.

To your example, isEven!1 will execute the line of code that is deemed to be
unreachable.

The issue here is that the compiler can't "try all possibilities" to see if it
will be able to find a path to that code (halting problem).

So probably we should turn off that feature when the code has taken a branch
based on a template constant or a static if. The compiler should assume the
other branch could be executed for a different instantiation, and so not
complain for this one.

I don't think there's a "right" way to handle this. The error in question is
truly a function of optimization and folding, but the user sees things in terms
of lines of code. To say a line of code may not be executed if you call it one
way is an error, even though it will be executed if you call it another way,
doesn't make a lot of sense. If we are going to be "helpful", we should at
least be accurate.

This is coming from someone who doesn't know how the compiler is implemented,
or doesn't even know how compilers are implemented. So perhaps this is too
difficult a task?

BTW, I was also saying that you *could* fix the problem without dummy variables
or recursion, but I agree that the compiler is being unhelpful here.

--


More information about the Digitalmars-d-bugs mailing list