digitalmars.D.bugs - [Issue 20603] New: 'cannot use non-constant CTFE pointer in an
- d-bugmail puremagic.com (38/38) Feb 23 2020 https://issues.dlang.org/show_bug.cgi?id=20603
https://issues.dlang.org/show_bug.cgi?id=20603 Issue ID: 20603 Summary: 'cannot use non-constant CTFE pointer in an initializer' in recursive structure with overlap Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: dkorpel live.nl This does not compile: ``` struct Base { union { int overlap; immutable(Sub)* sub; } this(Sub) { sub = new Sub; } } struct Sub { Base base; } immutable c0 = Base(Sub.init); ``` Error: cannot use non-constant CTFE pointer in an initializer Base(, &Sub0(Base(0, __void))) If you swap the order of the `overlap` and `sub` field, it compiles. If you change the field in `Sub` to be of a different type than `Base`, it compiles too. The exact limitations of CTFE and pointers to the data segment are not clear to me, but the above behavior is inconsistent and unclear. --
Feb 23 2020