digitalmars.D.bugs - [Issue 1268] New: Struct literals try to initialize static arrays of non-static structs incorrectly
- d-bugmail puremagic.com (38/38) Jun 15 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1268
- d-bugmail puremagic.com (9/9) Jun 26 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1268
- d-bugmail puremagic.com (8/8) Jul 23 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1268
http://d.puremagic.com/issues/show_bug.cgi?id=1268 Summary: Struct literals try to initialize static arrays of non- static structs incorrectly Product: D Version: 1.014 Platform: PC OS/Version: Windows Status: NEW Keywords: diagnostic, rejects-valid Severity: normal Priority: P3 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: deewiant gmail.com struct S { int[5] x; } void main() { S s = S(); } The above code fails to compile with the following errors: Error: cannot implicitly convert expression (0) of type int to int[5] Error: cannot cast int to int[5] (Notice the lack of line numbers.) The "S s = S();" line works at global scope, or when preceded by const or static. The only way to circumvent this is to add an initializer for each array element: struct S { //int[5] x = 0; // what the compiler tries: doesn't work //int[5] x = []; // void[0], not int[5] //int[5] x = cast(int[5])[]; // non-constant expression //int[5] x = [0]; // int[1], not int[5] as above // this works, but is tedious for long arrays // (although it can be automated with templates) int[5] x = [0,0,0,0,0]; } --
Jun 15 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1268 onlystupidspamhere yahoo.se changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED ------- Comment #1 from onlystupidspamhere yahoo.se 2007-06-26 14:26 ------- Fixed in 1.017. --
Jun 26 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1268 ------- Comment #2 from thomas-dloop kuehne.cn 2007-07-23 14:57 ------- Added to DStress as http://dstress.kuehne.cn/run/s/struct_initialization_12_A.d http://dstress.kuehne.cn/run/s/struct_initialization_12_B.d http://dstress.kuehne.cn/run/s/struct_initialization_12_C.d http://dstress.kuehne.cn/run/s/struct_initialization_12_D.d --
Jul 23 2007