digitalmars.D.bugs - [Issue 21231] New: Unreachable warning for empty struct in VariantN
- d-bugmail puremagic.com (40/40) Sep 08 2020 https://issues.dlang.org/show_bug.cgi?id=21231
https://issues.dlang.org/show_bug.cgi?id=21231 Issue ID: 21231 Summary: Unreachable warning for empty struct in VariantN with preview=fieldwise Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: phobos Assignee: nobody puremagic.com Reporter: moonlightsentinel disroot.org The following code produces an "unreachable code" warning when compiled with -preview=fieldwise: ================================================ struct Empty { bool opCmp(const scope ref Empty) const { return false; } } void main() { import std.variant : VariantN; Empty a, b; assert(a == b); assert(!(a < b)); VariantN!(4, Empty) v = a; assert(v == b); assert(!(v < b)); } ================================================ /dlang/dmd/linux/bin64/../../src/phobos/std/variant.d(261): Warning: statement is not reachable ================================================ The unreachable code follows an equality check for Empty which always returns true, causing an early exit in VariantN.handler.compare. This skips the checks for < and >. --
Sep 08 2020