[Issue 21231] New: Unreachable warning for empty struct in VariantN with preview=fieldwise

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 8 18:41:25 UTC 2020


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 at puremagic.com
          Reporter: moonlightsentinel at 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 >.

--


More information about the Digitalmars-d-bugs mailing list