Bug 10532 – Silence some unreachable statement warnings when in a static foreach
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-07-03T18:34:26Z
Last change time
2023-10-01T16:36:35Z
Keywords
pull
Assigned to
No Owner
Creator
Andrej Mitrovic
Comments
Comment #0 by andrej.mitrovich — 2013-07-03T18:34:26Z
-----
import std.traits;
enum E { a, b}
void main()
{
foreach (e; EnumMembers!E)
{
if (e == E.a)
continue;
// lots of code follows..
auto x = 1;
}
}
-----
$ dmd -w test.d
> test.d(14): Warning: statement is not reachable
I don't know if this is doable, but it's a little annoying that we have these unreachable statement warnings when in a static foreach loop. It forces use to use an else statement, but this introduces indentation.
In this specific test-case the alternative could be to Filter!() through the EnumMembers so "E.a" never appears in the loop, but for more complex cases such filtering may not be usable.
Comment #1 by dlang-bot — 2023-09-21T12:48:45Z
@adamdruppe updated dlang/dmd pull request #15568 "make D great again" fixing this issue:
- Fix 10532, 14835, 20522 by adding test cases
https://github.com/dlang/dmd/pull/15568
Comment #2 by dlang-bot — 2023-10-01T16:36:35Z
dlang/dmd pull request #15568 "make D great again" was merged into master:
- cfd7cfd4382803e0252ebe1cf13d4c39a60209e5 by Dennis Korpel:
Fix 10532, 14835, 20522 by adding test cases
https://github.com/dlang/dmd/pull/15568