D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6691 - static constructor inside template cannot initialize immutable template members
Summary: static constructor inside template cannot initialize immutable template members
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2011-09-18 18:43 UTC by Kenji Hara
Modified: 2011-09-21 00:02 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kenji Hara 2011-09-18 18:43:52 UTC
Follwing should compile, but can't.

template Hoge()
{
    immutable static int[int] dict;
    immutable static int value;

    static this()
    {
        dict = [1:1, 2:2];
        value = 10;
    }
}
alias Hoge!() H;
Comment 3 bearophile_hugs 2011-09-21 00:02:26 UTC
Keep in mind that there are cases more important than this one that currently don't work:


struct Foo {
    immutable int[1] arr;
    this(int x) {
        arr[0] = 1;
    }
}
auto f = Foo(1);
void main() {}