Bug 23266 – Dead else blocks are not considered unreachable
Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2022-07-22T07:37:30Z
Last change time
2023-11-14T18:13:10Z
Assigned to
No Owner
Creator
FeepingCreature
Comments
Comment #0 by default_357-line — 2022-07-22T07:37:30Z
This code, built with -w, gives a "statement is not reachable" warning on the second return:
void main() {
if (true) return;
return;
}
This code does not:
void main() {
if (true) return;
else return;
}
This despite the else block being just as unreachable.
Comment #1 by default_357-line — 2022-07-22T07:47:54Z
One could argue that this is correct because otherwise the common technique of stubbing out an if statement by adding `if (false &&` stops working. For the CompoundStatement error to trigger with that, you'd need to do `if (true &&`, which is much more rare.
Comment #2 by default_357-line — 2022-07-22T07:59:30Z
I've tried a DMD branch that errors with -w if `if()` has a statically known true condition and an else block. The two main things I ran into in Phobos are:
1.
if (false) {
some code that should affect function attributes but never be run;
}
2.
if (...) that should be static if (...)
For one the warning is useful, for the other it's harmful...
Comment #3 by schveiguy — 2023-11-14T17:12:16Z
The unreachable code warning will be disabled in the next release of the compiler.
https://github.com/dlang/dmd/pull/15568
I suggest we close this. WONTFIX? There's no MOOT status!
Comment #4 by default_357-line — 2023-11-14T18:13:10Z