[Issue 16297] New: Immutable data with statically-known initializer should be implicitly "static"
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Jul 19 06:13:54 PDT 2016
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 at puremagic.com
Reporter: andrei at 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.
--
More information about the Digitalmars-d-bugs
mailing list