[Issue 19774] New: wrong code caused by generic variadic opIndex

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Mar 30 01:57:53 UTC 2019


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

          Issue ID: 19774
           Summary: wrong code caused by generic variadic opIndex
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: ilyayaroshenko at gmail.com

alias AliasSeq(T...) = T;

struct C(T)
{
    T* ptr;

    ~this()
    {
        ptr = null;
    }

    auto bar() const 
    {
        return C!(const T)(ptr);
    }

    auto opIndex(A...)(A a)
    {
        return this;
    }

    auto foo() const
    {
        alias A = AliasSeq!();
        A a;
        return this.bar()[a];
        /+
        If we replace the line above with
        the following line
        then the code would work well
        +/
        //return this.bar.opIndex(a);
    }
}

void main()
{
    const d = C!double(new double);
    auto c = d.foo;
    // Fails if `this.bar[a];` is used
    // and pass if `this.bar.opIndex(a)` is used.
    // Expected behaviour: pass for both cases.
    assert(c.ptr !is null);
}

--


More information about the Digitalmars-d-bugs mailing list