www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19517] New: Spurious compiler warning with const toHash and


          Issue ID: 19517
           Summary: Spurious compiler warning with const toHash and alias
                    this classes
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: hsteoh quickfur.ath.cx

class C { }
struct S
    C c;
    alias c this;
Nullable!S s;

struct Nullable(T) // reduced from std.typecons.Nullable
    union U
        T t;

    U u = U.init;

    size_t toHash() const  safe nothrow
        static if (__traits(compiles, .hashOf(u.t))) {}
        return 0;

Compiler output:
Warning: struct S has method toHash, however it cannot be called with const(S)

This warning is spurious, because the whole point of the static if is to check
for exactly this case, and to provide workaround code for it.  As things stand,
it is impossible to avoid the warning, even if there is workaround code for it.

bug here, however, is related the compiler, and appears to be related to the
compiler confusing Nullable.toHash with S.c.toHash because of the `alias this`.

Dec 26 2018