[Issue 13688] New: 'in' expression for AA not detected as GC usage

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Nov 5 03:58:48 PST 2014


https://issues.dlang.org/show_bug.cgi?id=13688

          Issue ID: 13688
           Summary: 'in' expression for AA not detected as GC usage
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: sinkuupump at gmail.com

'in' expression for AA calls KeyType.toHash/opEquals if exist, but not detected
as GC usage even if these functions are not @nogc.

Example: (In this case, compiler should require that toHash/opEquals are
@nogc.)
struct KeyType
{
    int x;

    size_t toHash() const @safe nothrow
    {
        return x;
    }

    bool opEquals(in KeyType r) const
    {
        return x == r.x;
    }
}

ulong func(ulong[KeyType] aa) @nogc
{
    if (auto p = KeyType(10) in aa) // can call KeyType.toHash/opEquals
        return *p;

    return aa.length;
}

--


More information about the Digitalmars-d-bugs mailing list