[Issue 21878] New: "ref" lost when indexing array in CTFE

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Apr 29 17:36:17 UTC 2021


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

          Issue ID: 21878
           Summary: "ref" lost when indexing array in CTFE
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: CTFE
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dlang-bugzilla at thecybershadow.net

///////////////////////////////// test.d ////////////////////////////////
struct A
{
    int i;
    ref inout(int) opIndex(size_t idx) inout return { return i; }
}

struct B
{
    A[1] a;
    ref inout(int) opIndex(size_t idx) inout return { return a[0][idx]; }
}

bool ctfeFunc()
{
    A a;
    a[0] = 42;
    assert(a[0] == 42); // OK

    B b;
    b[0] = 42;
    assert(b[0] == 42); // fails

    return true;
}
enum eval = ctfeFunc();

unittest
{
    ctfeFunc(); // succeeds at runtime
}
/////////////////////////////////////////////////////////////////////////

It looks like the assignment is going into some rvalue which is then lost.

--


More information about the Digitalmars-d-bugs mailing list