www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24354] New: Static arrays are by-reference during CTFE

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

          Issue ID: 24354
           Summary: Static arrays are by-reference during CTFE
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: CTFE, wrong-code
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dlang-bugzilla thecybershadow.net

The following function returns a different result at compile-time vs. runtime:

auto fun()
{
    ubyte[1] arr = [0];
    auto copy = arr;
    copy[0] = 42;
    return arr;
}

// E.g.
void main()
{
    static ct = fun();
    assert(ct == fun());
}

I think this a regression introduced in https://github.com/dlang/dmd/pull/3467.

--
Jan 23