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

          Issue ID: 16297
           Summary: Immutable data with statically-known initializer
                    should be implicitly "static"
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: [email protected]
          Reporter: [email protected]

This came up during the review of https://github.com/dlang/dmd/pull/5938.
Consider:

int fun(ubyte[] b)
{
  immutable ubyte[4] d = [0x7F, 'E', 'L', 'F'];
  return b[] == d[];
}

int gun(ubyte[] b)
{
  static immutable ubyte[4] d = [0x7F, 'E', 'L', 'F'];
  return b[] == d[];
}

By http://goo.gl/mxaVKe, different code is generated for these functions;
namely, the immutable data in fun() is initialized with every call. An
optimization would allocate that data statically.

--

Reply via email to