[Issue 14835] Statement is not reachable doesn't play along generic code
https://issues.dlang.org/show_bug.cgi?id=14835 Andrei Alexandrescu changed: What|Removed |Added CC||and...@erdani.com --- Comment #10 from Andrei Alexandrescu --- One simple possibility here is to automatically insert `else` whenever the `static if` branch does not fall through --
[Issue 14835] Statement is not reachable doesn't play along generic code
https://issues.dlang.org/show_bug.cgi?id=14835 --- Comment #9 from anonymous4 --- (In reply to Walter Bright from comment #8) > but I wonder about its affect on existing code. Will it disable all unreachable code checks? Try this: int square(int num) { if(true)return 0; return num * num; } --
[Issue 14835] Statement is not reachable doesn't play along generic code
https://issues.dlang.org/show_bug.cgi?id=14835 Walter Bright changed: What|Removed |Added CC||bugzi...@digitalmars.com --- Comment #8 from Walter Bright --- It seems the problem lies here: https://github.com/dlang/dmd/blob/master/src/statement.d#L453 if (s.condition.isBool(true)) { if (s.ifbody) result |= s.ifbody.blockExit(func, mustNotThrow); else result |= BEfallthru; } else if (s.condition.isBool(false)) { if (s.elsebody) result |= s.elsebody.blockExit(func, mustNotThrow); else result |= BEfallthru; } else Having it set BEfallthru as if both ifbody and elsebody could execute should work, but I wonder about its affect on existing code. --
[Issue 14835] Statement is not reachable doesn't play along generic code
https://issues.dlang.org/show_bug.cgi?id=14835 Les De Ridder changed: What|Removed |Added CC||dl...@lesderid.net --
[Issue 14835] Statement is not reachable doesn't play along generic code
https://issues.dlang.org/show_bug.cgi?id=14835 Steven Schveighoffer changed: What|Removed |Added See Also||https://issues.dlang.org/sh ||ow_bug.cgi?id=16201 --
[Issue 14835] Statement is not reachable doesn't play along generic code
https://issues.dlang.org/show_bug.cgi?id=14835 Jack Stouffer changed: What|Removed |Added CC||j...@jackstouffer.com Severity|normal |major --- Comment #7 from Jack Stouffer --- This has come up again: https://github.com/dlang/phobos/pull/4287 This issue is a major annoyance when writing template code and almost anyone writing optimized code with static if's will run into it eventually, so I'm raising the importance of this. --
[Issue 14835] Statement is not reachable doesn't play along generic code
https://issues.dlang.org/show_bug.cgi?id=14835 Marc Schütz changed: What|Removed |Added CC||schue...@gmx.net --
[Issue 14835] Statement is not reachable doesn't play along generic code
https://issues.dlang.org/show_bug.cgi?id=14835 --- Comment #6 from thomas.bock...@gmail.com --- Here's a minimal compilable (requires dmd argument -wi, rather than -w) example, for anyone trying to fix this: module main; import std.stdio; void reachIf(bool x)() { if(!x) return; writeln("reached"); // Warning: statement is not reachable } void main(string[] args) { reachIf!true(); // prints "reached" reachIf!false(); // triggers warning } --
[Issue 14835] Statement is not reachable doesn't play along generic code
https://issues.dlang.org/show_bug.cgi?id=14835 thomas.bock...@gmail.com changed: What|Removed |Added CC||thomas.bock...@gmail.com --- Comment #5 from thomas.bock...@gmail.com --- This issue will block for further improvements to constant folding and value range propagation, as better folding and VRP make it noticeably worse. I found this out by adding VRP-based constant folding for integer comparisons, and then trying to compile Phobos and vibe.d - see: https://github.com/D-Programming-Language/dmd/pull/5229 --
[Issue 14835] Statement is not reachable doesn't play along generic code
https://issues.dlang.org/show_bug.cgi?id=14835 --- Comment #4 from Steven Schveighoffer --- 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. --
[Issue 14835] Statement is not reachable doesn't play along generic code
https://issues.dlang.org/show_bug.cgi?id=14835 --- Comment #3 from Mathias LANG --- Note that with this implementation you get an error (missing return) in 2.068.0, but 2.069.0-b1 fixed that. But the point is not about the actual implementation, but the effect of this warning. It makes meta code much harder to write that it's needed, and way less natural. Will you accept a language where every `if` statement has to be followed by an `else` statement ? --
[Issue 14835] Statement is not reachable doesn't play along generic code
https://issues.dlang.org/show_bug.cgi?id=14835 Steven Schveighoffer changed: What|Removed |Added CC||schvei...@yahoo.com --- Comment #2 from Steven Schveighoffer --- Why can't the "hack" variable be eliminated by enclosing the rest of the function in the else branch? And what about this solution for the group comparison (copied from my post in Issue 15166): private bool compare(alias Group1, alias Group2)() { foreach (index, element; Group!(Group1.expand, void).expand) { static if(index == Group1.expand.length) return true; else static if (!is(Group1.expand[index] == Group2.expand[index])) return false; } } Neither requires recursion. --
[Issue 14835] Statement is not reachable doesn't play along generic code
https://issues.dlang.org/show_bug.cgi?id=14835 Martin Nowak changed: What|Removed |Added CC||c...@dawg.eu --- Comment #1 from Martin Nowak --- *** Issue 15166 has been marked as a duplicate of this issue. *** --