digitalmars.D.learn - SList and DList init doesn't work in global variable
- Martin Krejcirik (13/13) Sep 28 2015 Is this intended or known issue ? It works with 2.066.
- =?UTF-8?Q?Ali_=c3=87ehreli?= (36/47) Sep 28 2015 Yes, it looks like there are problems with their implementations. Those
Is this intended or known issue ? It works with 2.066. SList!int gslist = [1,2,3,4,5,6]; // broken since 2.067 // Error: reinterpreting cast from NodeWithoutPayload* to Node* is not supported in CTFE DList!int gdlist = [1,2,3,4,5,6]; // broken since 2.067 // Error: non-constant expression ... void main() { SList!int lslist = [1,2,3,4,5,6]; // OK DList!int ldlist = [1,2,3,4,5,6]; // OK } -- mk
Sep 28 2015
On 09/28/2015 02:15 PM, Martin Krejcirik wrote:Is this intended or known issue ? It works with 2.066. SList!int gslist = [1,2,3,4,5,6]; // broken since 2.067 // Error: reinterpreting cast from NodeWithoutPayload* to Node* is not supported in CTFE DList!int gdlist = [1,2,3,4,5,6]; // broken since 2.067 // Error: non-constant expression ... void main() { SList!int lslist = [1,2,3,4,5,6]; // OK DList!int ldlist = [1,2,3,4,5,6]; // OK }Yes, it looks like there are problems with their implementations. Those questions aside, I would initialize such module variables in a module static this() anyway: import std.container; SList!int gslist; DList!int gdlist; static this() { gslist = [1,2,3,4,5,6]; gdlist = [1,2,3,4,5,6]; } void main() { } If you want the lists to be immutable, then the following initialization pattern works: import std.container; immutable SList!int gslist; immutable DList!int gdlist; auto init_gslist() { return SList!int([1,2,3,4,5,6]); } auto init_gd_list() { return DList!int([1,2,3,4,5,6]); } static this() { gslist = init_gslist(); gdlist = init_gd_list(); } void main() { } The fact that I needed the two module-level init_* functions is also problematic, right? For example, moving those inside static this() does not work. Ali
Sep 28 2015