digitalmars.D.bugs - [Issue 15694] New: Initializing static array member of a type that
- via Digitalmars-d-bugs (53/53) Feb 17 2016 https://issues.dlang.org/show_bug.cgi?id=15694
https://issues.dlang.org/show_bug.cgi?id=15694 Issue ID: 15694 Summary: Initializing static array member of a type that has disabled default constructor Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: acehreli yahoo.com Related newsgroup thread: http://forum.dlang.org/thread/bgmzajszxajcuoqtkahq forum.dlang.org?page=1 The following constructor fails compilation in a way that suggests some error in the order members are initialized. import std.stdio; struct Foo { int i; /* This line is pertinent: */ disable this(); this(int i) { this.i = i; } } struct FooList { Foo[3] foos; this(int) { /* This constructor fails compilation with dmd 2.070.0: * * Error: field 'foos' initialization is not allowed in loops or * after labels * * There are at least two interesting ways of passing compilation: * * a) Either add the following line BEFORE the loop: * foos[0] = Foo(10); * * b) Or remove 'ref' in the loop AND add the following line AFTER * the loop: * foos[0] = Foo(10); */ foreach (ref f; foos[]) { writeln(f.i); } } } void main() { } Ali --
Feb 17 2016