www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16297] New: Immutable data with statically-known initializer

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: nobody puremagic.com
          Reporter: andrei erdani.com

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.

--
Jul 19 2016