Compiled with -w the code:
import std;
void main() {
auto x = only(1).chain(repeat(2));
}
gives the following errors:
/dlang/dmd/linux/bin64/../../src/phobos/std/range/package.d(1010): Warning: statement is not reachable
/dlang/dmd/linux/bin64/../../src/phobos/std/range/package.d(1011): Warning: statement is not reachable
Error: warnings are treated as errors
Use -wi if you wish to treat warnings only as informational.
So does the following where I have isolated chain:
import std.range : chain;
struct RepeatOne {
enum empty = false;
const front = 1;
const back = 1;
void popFront() {}
void popBack() {}
auto save() { return RepeatOne.init; }
}
struct OnlyOne {
bool empty = true;
auto front = 1;
auto back = 1;
void popFront() { empty=false; }
void popBack() { empty=false; }
auto save() { return typeof(this)(this.tupleof); }
}
void main() {
auto x = OnlyOne.init.chain(RepeatOne.init);
}
Comment #1 by dlang-bot — 2023-09-12T17:29:39Z
@jamesragray created dlang/phobos pull request #8812 "chain unreachable code - Issue 24143" fixing this issue:
- Added unittest for Issue 24143
- fix Issue 24143
https://github.com/dlang/phobos/pull/8812
Comment #2 by robert.schadek — 2024-12-01T16:41:47Z