www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21231] New: Unreachable warning for empty struct in VariantN


          Issue ID: 21231
           Summary: Unreachable warning for empty struct in VariantN with
           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

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