Bug 20603 – 'cannot use non-constant CTFE pointer in an initializer' in recursive structure with overlap

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-02-23T21:27:24Z
Last change time
2022-04-05T08:28:31Z
Keywords
pull
Assigned to
No Owner
Creator
Dennis
See also
https://issues.dlang.org/show_bug.cgi?id=11268

Comments

Comment #0 by dkorpel — 2020-02-23T21:27:24Z
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.
Comment #1 by dlang-bot — 2020-03-09T23:08:13Z
@dkorpel created dlang/dmd pull request #10882 "Fix issue 20603 - 'cannot use non-constant CTFE pointer in an initializer' in recursive structure with overlap" fixing this issue: - fix issue 20603 https://github.com/dlang/dmd/pull/10882
Comment #2 by dlang-bot — 2022-04-05T08:28:31Z
dlang/dmd pull request #10882 "Fix issue 20603 - 'cannot use non-constant CTFE pointer in an initializer' in recursive structure with overlap" was merged into master: - ee44aa8da03b0dbc85e092932e3c9198a8e0a19b by dkorpel: fix issue 20603 https://github.com/dlang/dmd/pull/10882